Pipeline and step conditions

With Pipeline and StepConditions, criteria can get defined if and when:
  • A pipeline gets created

  • or a step may get executed

PipelineConditions

Pipeline conditions define whether a pipeline may get automated or to which criteria it may get created

  • Custom conditions can get implemented with the \TechDivision\ProcessPipelines\Api\PipelineConditionInterface, which can get used in a Pipeline XML

  • The isReady function defines when a pipeline may get created with the heartbeat

The components already include the following standardized pipeline conditions:
Name Description

NoAutoSpawn

The NoAutoSpawn condition prevents the execution of pipelines to a heartbeat.

  • This condition should get used if pipelines are not allowed to be executed, e.g., every minute.

NoSiblingInProgress

The NoSiblingInProgress condition checks whether another pipeline with the same name is active, i.e., has the status running.

WebsiteActive

Depending on the implementation, pipelines can run committed for individual Magento websites.

  • It gets checked if websites are active

CronExpression

With the CronExpression condition, pipelines can be created at defined times, e.g., at 01:00 at night.

  • It gets checked if the stored cron expression

    • is reached

    • execution is within the heartbeat pulse

Example of virtualization of the CronExpression
<!-- Pipeline pacemaker indexer cron conditions -->
<virtualType
        name="TechDivision\PacemakerIndexer\Virtual\Condition\Pipeline\IndexerCronExpression" type="TechDivision\ProcessPipelines\Helper\Condition\Pipeline\CronExpression">
    <arguments>
        <argument name="data" xsi:type="array">
            <item name="cron_expression" xsi:type="string">* * * * *</item>
        </argument>
    </arguments>
</virtualType>

IndexerCronExpression is deprecated.

ConfigurableCronExpression

The ConfigurableCronExpression is an extension of the CronExpression condition.

  • The DI controllable cron printout can get made configurable with a stored Magento backend configuration

  • It gets checked if the CronExpression, which can get configure

    • is reached

    • and if it is within the heartbeat pulse

  • This implementation gets used for the cleanup pipeline

PausePipelineExecution

The PausePipelineExecution condition can be used to suspend pipelines execution within a defined period (per minute).

  • It checks when the last pipeline got completed by name

  • No other pipeline with the same name may be created and executed within the defined time period

  • The condition can be customized using a DI for desired pipelines

Virtualization of pause condition for cleanup pipeline vendor/techdivision/process-pipelines/etc/di.xml
<!-- Pipeline pacemaker indexer pause pipeline condition -->
<virtualType
        name="TechDivision\ProcessPipelines\Virtual\Condition\Pipeline\PauseCleanupPipelineExecutionCondition" type="TechDivision\ProcessPipelines\Helper\Condition\Pipeline\PausePipelineExecutionCondition">
    <arguments>
        <argument name="pipelineName" xsi:type="string">clean_up_pipelines</argument>
        <argument name="timeSpan" xsi:type="string">1 minutes</argument>
    </arguments>
</virtualType>

DependingOnNamedPipelines

The DependingOnNamedPipelines condition checks whether another pipelines with given names are in a given status i.e., has the status running.

  • It checks the given pipelines for given status

  • The condition (pipelines and status) can be customized using a DI for desired pipelines

Virtualization of depending named pipeline condition for initializer pipeline vendor/techdivision/pacemaker-pipeline-initializer/etc/di.xml
<virtualType
        name="TechDivision\PacemakerPipelineInitializer\Virtual\Condition\Pipeline\DependingOnInitPipelines" type="TechDivision\ProcessPipelines\Helper\Condition\Pipeline\DependingOnNamedPipelines">
    <arguments>
        <argument name="pipelineNames" xsi:type="array">
            <item name="pacemaker_pipeline_initizializer" xsi:type="string">pacemaker_pipeline_initizializer</item>
        </argument>
        <argument name="status" xsi:type="string">running</argument>
    </arguments>
</virtualType>

ConfigurationFlagEnabled

The ConfigurationFlagEnabled condition checks if a given configuration flags by path are active or not.

  • It checks the given configuration paths for active status

  • The condition can be customized using a DI for desired pipelines

StepConditions

  • Steps are created together with a pipeline

  • Step conditions define whether a step can/must get executed or not

  • With the \TechDivision\ProcessPipelines\Api\StepConditionInterface, own conditions can get implemented, and later get used in a pipeline.xml

  • The isReady function gets used to define when a step can or may get executed with the heartbeat

The components already include the following set of standardized step conditions:
Name Description

AttemptsLimit

With the AttemptsLimit condition, a step’s number of repetitions can be defined.

  • A step can get executed e.g. up to 5 times in the succession of the heartbeat, should errors occur during processing

  • If the error is still present after the 5th time, the pipeline gets aborted, or the step gets no longer executed

Virtualization of the AttemptsLimit vendor/techdivision/process-pipelines/etc/di.xml
<virtualType name="TechDivision\ProcessPipelines\Helper\Condition\Step\AttemptsLimit\Limit5" type="TechDivision\ProcessPipelines\Helper\Condition\Step\AttemptsLimit">
    <arguments>
        <argument name="data" xsi:type="array">
            <item name="limit" xsi:type="string">5</item>
        </argument>
    </arguments>
</virtualType>

TimeBetweenAttempts

With the TimeBetweenAttempts condition, you define a waiting time for the re-execution.

  • If a step fails and it starts more attempts with the AttemptsLimit condition, these would always get executed with the next heartbeat

  • With the condition, for example, 5 minutes (the default is 5 heartbeats) can get skipped before the step gets executed again

Example concerning a 5-minute waiting time is available in the component DI:
Virtualization of TimeBetweenAttempts vendor/techdivision/process-pipelines/etc/di.xml
<virtualType name="TechDivision\ProcessPipelines\Helper\Condition\Step\TimeBetweenAttempts\Minutes5"
             type="TechDivision\ProcessPipelines\Helper\Condition\Step\TimeBetweenAttempts">
    <arguments>
        <argument name="data" xsi:type="array">
            <item name="minutes" xsi:type="string">5</item>
        </argument>
    </arguments>
</virtualType>

WaitForStepIsNotRunning

The WaitForStepIsNotRunning condition can get used to define wait or execution cycles due to running steps.

  • Step names can get passed to the condition with the step_names argument list

    • A step with a WaitForStepIsNotRunning operation can only get executed as long as no steps defined in the arguments are running in other pipelines

PreviousStepsCompleted

With the PreviousStepsCompleted condition, a step gets only executed if all previous steps of a lower sort order or have a valid and successful end state.

  • Only the step statuses success and skipped are considered

PreviousStepsFinished

With the PreviousStepsFinished condition, a step gets executed if all previous steps have a lower sort order or a valid final state.

  • Only the execution statuses pending, enqueued and running are NOT observed

NamedPipelinesHasStatus

With the NamedPipelinesHasStatus condition, a step gets executed if no given pipelines with given status was found.

Example of a virtual NamedPipelinesHasStatus Condition
<virtualType
        name="TechDivision\ProcessPipelines\Helper\Condition\Step\NoRunningImportPricePipeline" type="TechDivision\ProcessPipelines\Helper\Condition\Step\NamedPipelinesHasStatus">
    <arguments>
        <argument name="pipelineNames" xsi:type="array">
            <item name="pacemaker_import_price" xsi:type="string">pacemaker_import_price</item>
        </argument>
        <argument name="status" xsi:type="string">running</argument>
    </arguments>
</virtualType>

DependingOnNamedSteps

With the DependingOnNamedSteps condition, a step gets executed if another specific steps of the pipeline are finished successfully (success, skipped).

  • It checks the given steps for given status

  • The condition (steps and status) can be customized using a DI for desired pipelines

  • The status is a comma separated string, the steps an array

Example of a virtual DependingOnNamedSteps condition depending on two specific steps in a pipeline.
<virtualType name="TechDivision\PacemakerPipelineInitializer\Virtual\Condition\Step\DependingOnABCXXX" type="TechDivision\ProcessPipelines\Helper\Condition\Step\DependingOnNamedSteps">
    <arguments>
        <argument name="stepNames" xsi:type="array">
            <item name="pacemaker_step_ABC" xsi:type="string">pacemaker_step_ABC</item>
            <item name="pacemaker_step_XXX" xsi:type="string">pacemaker_step_XXX</item>
        </argument>
        <argument name="status" xsi:type="string">success</argument>
    </arguments>
</virtualType>

DelayTime

With the DelayTime condition, a step gets executed after a configured time after its creation.

  • It checks the creation datetime of the step

  • Several virtualization are provided via DI for different delay times

This condition is particularly useful for the first steps of pipelines so that they are not executed with the same heartbeat immediately after the pipeline is created

Example of a virtual DelayTime condition to wait three minutes after creation.
<virtualType name="TechDivision\ProcessPipelines\VirtualType\Helper\Condition\Step\DelayTime\Minute3"
             type="TechDivision\ProcessPipelines\Helper\Condition\Step\DelayTime">
    <arguments>
        <argument name="data" xsi:type="array">
            <item name="minute" xsi:type="string">3</item>
        </argument>
    </arguments>
</virtualType>