How to create a step condition
Step Conditions
Each step can have conditions, which implement the TechDivision\ProcessPipelines\Api\StepConditionInterface
interface.
Existing Conditions
There are some ready-to-use conditions.
TechDivision\ProcessPipelines\Helper\Condition\Step\PreviousStepsCompleted
-
Run the given step only if the previous steps are successfully finished.
TechDivision\ProcessPipelines\Helper\Condition\Step\PreviousStepsFinished
-
Run the given step only if the previous steps are not in a pending, running or enqueued state.
Usage
See How to configure a pipeline for more details about the XML structure. |
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:TechDivision/ProcessPipelines/etc/pipeline.xsd">
<pipeline name="example_pipeline" description="Example pipeline">
...
<step name="my_third_step" executorType="MyCompany\MyModule\Model\Executor\DoSomeThing" sortOrder="1522" description="" runAlwaysStep="">
<conditions>
<step_condition type="TechDivision\ProcessPipelines\Helper\Condition\Step\PreviousStepsCompleted" description="Run only after previous"/>
</conditions>
</step>
...
</pipeline>
</config>
Virtual Conditions
Template Conditions
By using the virtualType
feature of Magento’s DI it is easy to create new conditions with some new params.
Therefore there are some "template" conditions.
TechDivision\ProcessPipelines\Helper\Condition\Step\AttemptsLimit
-
Limitation of retries for given steps.
TechDivision\ProcessPipelines\Helper\Condition\Step\TimeBetweenAttempts
-
Timeout between retries.
TechDivision\ProcessPipelines\Helper\Condition\Step\WaitForStepIsNotRunning
-
Disables execution of a step while the defined steps (even in other pipelines) are running. For example: only one import process at the same time possible…
TechDivision\PacemakerImportBase\Model\Condition\Step\NoConflictingStepsInProcess
-
The list of conflicting step names can be set via DI. Verifies that this steps are not running or enqueued. This check works over all existing pipelines.
TechDivision\PacemakerImportBase\Model\Condition\Step\IsStageReady
-
This condition was designed to verify, whether a stage is ready to be executed.
Ready to use virtual conditions
TechDivision\ProcessPipelines\Helper\Condition\Step\AttemptsLimit\Limit1
-
Attempts limit 1
TechDivision\ProcessPipelines\Helper\Condition\Step\AttemptsLimit\Limit2
-
Attempts limit 2
TechDivision\ProcessPipelines\Helper\Condition\Step\AttemptsLimit\Limit5
-
Attempts limit 5
TechDivision\ProcessPipelines\Helper\Condition\Step\AttemptsLimit\Limit10
-
Attempts limit 10
TechDivision\ProcessPipelines\Helper\Condition\Step\TimeBetweenAttempts\Minutes5
-
5 minutes delay between attempts
TechDivision\ProcessPipelines\Helper\Condition\Step\TimeBetweenAttempts\Minutes15
-
15 minutes delay between attempts
TechDivision\ProcessPipelines\Helper\Condition\Step\TimeBetweenAttempts\Minutes30
-
30 minutes delay between attempts
Usage
In following example module virtual conditions are used to allow parallel execution. |
Create virtual spawn conditions using di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
...
<virtualType name="MyCompany\MyModule\Virtual\Condition\AttemptsLimit42" type="TechDivision\ProcessPipelines\Helper\Condition\Step\AttemptsLimit">
<arguments>
<argument name="data" xsi:type="array">
<item name="limit" xsi:type="string">42</item>
</argument>
</arguments>
</virtualType>
<virtualType name="MyCompany\MyModule\Virtual\Condition\TimeBetweenAttempts\Minutes42" type="TechDivision\ProcessPipelines\Helper\Condition\Step\TimeBetweenAttempts">
<arguments>
<argument name="data" xsi:type="array">
<item name="minutes" xsi:type="string">42</item>
</argument>
</arguments>
</virtualType>
<virtualType name="MyCompany\MyModule\Virtual\Condition\AllDownloadsAreReady" type="TechDivision\ProcessPipelines\Helper\Condition\Step\PreviousStepsCompleted">
<arguments>
<argument name="data" xsi:type="array">
<item name="step_filter" xsi:type="string">download_media_step,download_csv_step</item>
</argument>
</arguments>
</virtualType>
<virtualType name="MyCompany\MyModule\Virtual\Condition\NoImportIsRunning" type="TechDivision\ProcessPipelines\Helper\Condition\Step\WaitForStepIsNotRunning">
<arguments>
<argument name="data" xsi:type="array">
<item name="step_names" xsi:type="string">import_stock_step,import_products_step</item>
</argument>
</arguments>
</virtualType>
...
</config>
Use the virtual condition in pipeline.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:TechDivision/ProcessPipelines/etc/pipeline.xsd">
<pipeline name="example_pipeline" description="Example pipeline">
...
<step name="some_step" executorType="MyCompany\MyModule\Model\Executor\DoSomeThing" sortOrder="10" description="" >
<conditions>
<step_condition type="MyCompany\MyModule\Virtual\Condition\AttemptsLimit42" description="Retry up to 42 times"/>
<step_condition type="TechDivision\ProcessPipelines\Helper\Condition\Step\TimeBetweenAttempts\Minutes5" description="Wait 5 minutes between attempts"/>
<step_condition type="MyCompany\MyModule\Virtual\Condition\AllDownloadsAreReady" description="Start only if downloads are ready"/>
<step_condition type="MyCompany\MyModule\Virtual\Condition\NoImportIsRunning" description="Ensure no other import process is active"/>
</conditions>
</step>
...
</pipeline>
</config>