How to create a pipeline condition
This documentation is not for the latest version Pacemaker version. Click here to switch to version 1.2 |
Pipeline Conditions
Each pipeline has at least one condition, which implements the
TechDivision\ProcessPipelines\Api\PipelineConditionInterface
interface.
Existing Conditions
There are some ready-to-use conditions.
TechDivision\ProcessPipelines\Helper\Condition\Pipeline\NoAutoSpawn
-
Disables auto spawning of given pipeline. Pipelines, which use this condition can not be spawned by
heartbeat
. TechDivision\ProcessPipelines\Helper\Condition\Pipeline\NoSiblingInProgress
-
Disable spawning of the given pipeline, while this pipeline is already in progress.
Usage
<?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">
<conditions>
<pipeline_condition type="TechDivision\ProcessPipelines\Helper\Condition\Pipeline\NoAutoSpawn" description="Disable auto spawning"/>
</conditions>
...
</pipeline>
</config>
Provide arguments from condition to steps
Since version 1.1.0 there is an additional interface
(TechDivision\ProcessPipelines\Api\ArgumentProviderInterface
) for conditions,
which enables you to provide arguments from the pipeline condition all pipeline steps.
Usage Examples
<?php
use TechDivision\ProcessPipelines\Api\PipelineConditionInterface;
use TechDivision\ProcessPipelines\Api\ArgumentProviderInterface;
class FileExistsCondition implements PipelineConditionInterface, ArgumentProviderInterface
{
const SOME_MAGIC_FILE_PATTERN = '...';
public function isReady(array $pipelineConfiguration)
{
$this->searchForFiles(self::SOME_MAGIC_FILE_PATTERN);
return $this->hasFiles();
}
public function getArguments()
{
return $this->getFiles();
}
}
Virtual 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\Pipeline\CronExpression
-
Defines execution time for a pipeline using regular cron expression.
TechDivision\ProcessPipelines\Helper\Condition\Pipeline\ConfigurableCronExpression
-
Defines execution time for a pipeline using regular cron expression, while this expression can be configured in Magento admin.
Usage
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\EveryNight" type="TechDivision\ProcessPipelines\Helper\Condition\Pipeline\CronExpression">
<arguments>
<argument name="data" xsi:type="array">
<item name="cron_expression" xsi:type="string">0 2 * * *</item>
</argument>
</arguments>
</virtualType>
<virtualType name="MyCompany\MyModule\Virtual\Condition\FullImport" type="TechDivision\ProcessPipelines\Helper\Condition\Pipeline\ConfigurableCronExpression">
<arguments>
<argument name="data" xsi:type="array">
<item name="config_path" xsi:type="string">my_module/crontab/full_import</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="Some example pipeline">
<conditions>
<pipeline_condition type="MyCompany\MyModule\Virtual\Condition\EveryNight" description="Run once in the night"/>
</conditions>
...
</pipeline>
<pipeline name="another_example_pipeline" description="Some example pipeline">
<conditions>
<pipeline_condition type="MyCompany\MyModule\Virtual\Condition\FullImport" description="Customer defined cron expression"/>
</conditions>
...
</pipeline>
</config>