Step condition

The base of the step conditions is in the Process Pipelines component.

  • The import pipeline component offers different standardized step conditions

  • See Process Pipelines

NoConflictingIndexStepProcess - virtual

Virtual extension with Magento DI of NoConflictingStepsInProcess.

  • The system checks whether the steps pacemaker_import_reindex or pacemaker_force_reindex gets currently executed

Virtualization NoConflictingIndexStepProcess vendor/techdivision/pacemaker-indexer/etc/di.xml
<virtualType name="TechDivision\PacemakerIndexer\Virtual\Condition\NoConflictingIndexStepProcess" type="TechDivision\PacemakerImportBase\Model\Condition\Step\NoConflictingStepsInProcess">
    <arguments>
        <argument name="stepNames" xsi:type="array">
            <item name="pacemaker_import_reindex" xsi:type="string">
                pacemaker_import_reindex
            </item>
            <item name="pacemaker_force_reindex" xsi:type="string">
                pacemaker_force_reindex
            </item>
        </argument>
    </arguments>
</virtualType>

NoConflictingIndexingProcess

The NoConflictingIndexingProcess condition is used to check whether a currently executing indexing process should be excluded.

  • The database entry of the indexer is checked

    • If an index status gets set to work, the condition in the isReady function returns false

  • Running delta indexing processes and manual full reindex processes must get considered

  • This conditions can be customized:

    • via Admin configuration in PACEMAKER Pipeline Settings Indexer Settings Excluded Indexers on global level.

    • via Magento DI as a virtual type for specific index/import behaviour.

Example:

<virtualType name="TechDivision\PacemakerImportBase\Virtual\Condition\NoConflictingCustomIndexingProcess" type="TechDivision\PacemakerImportBase\Model\Condition\Step\NoConflictingIndexingProcess">
    <arguments>
        <argument name="excludedIndexer" xsi:type="array">
            <item name="custom_dummy_indexer" xsi:type="string">custom_dummy_indexer</item>
        </argument>
    </arguments>
</virtualType>

NoImportExecStepIsRunning

A special condition that checks whether an import executor is running.

Implementation isReady vendor/techdivision/pacemaker-import-base/Model/Condition/Step/NoImportExecStepIsRunning.php
<?php
public function isReady(StepInterface $step): bool
{
    $searchCriteria = $this->searchCriteriaBuilder
        ->addFilter(
            StepInterface::FIELD_STATUS,
            [
                StepInterface::STATUS_RUNNING,
                StepInterface::STATUS_ENQUEUED,
            ],
            'in'
        )
        ->create();
    $steps = $this->getStepsList->execute($searchCriteria)->getItems();
    foreach ($steps as $stepItem) {
        $executorTypeInst =
            ObjectManager::getInstance()->get($stepItem['executor_type']);
        if ($executorTypeInst instanceof ImportExecutor) {
            return false;
        }
    }
    return true;
}

NoExceedMaxTime

The NoExceedMaxTime condition can be used to define wait or execution cycles of import steps.

  • The Configuration can be used to define how long an index operation may lie in the past

  • 10 minutes are defined as the standard

  • If an index run is longer than the configured time span in the past, the next import steps, if they have this condition, are paused from execution and are only executed further after an index operation has taken place

CouldSkipByNoFiles

The CouldSkipByNoFiles condition can be used to check whether import files exist based on import steps.

  • This condition is useful for pipelines with multiple import steps when special files for imports do not exist

  • The pipeline gets created using a general file pattern, but within the steps, it gets rechecked to see if data can get processed for the specific import

  • That is the case in the standard catalog import

  • The standard catalog import can get optimized with this condition because the condition of the step sets the status to skipped even before execution

Implementation isReady vendor/techdivision/pacemaker-import-base/Model/Condition/Step/CouldSkipByNoFiles.php
<?php
public function isReady(StepInterface $step): bool
{
    if (!$this->hasValidFiles($step)) {
        $step->setLog('Marked as skipped because there no files to process');
        $step->setStatus(StepInterface::STATUS_SKIPPED);
        $step->setFinishedAt($this->stepRepository->getDatetime()->gmtDate());
        $this->stepRepository->save($step);
        return false;
    } else {
        return true;
    }
}

This condition can get extended with Magento-DI and thus be used for each pipeline/import separately.

Example

Integration in Category Import:
Integration in pacemaker_import_catalog pipeline vendor/techdivision/pacemaker-import-catalog/etc/pipeline.xml
<pipeline name="pacemaker_import_catalog"
          description="Pacemaker Product Import"
          use-working-directory="true"
          expire-in="6 hours">
    <conditions>
        ...
    </conditions>
    ..
    <step name="category_import"
          executorType="TechDivision\PacemakerImportBase\Model\Executor\ImportExecutor"
          sortOrder="50" description="Import categories">
        <conditions>
            <step_condition type="TechDivision\PacemakerImportCatalog\Virtual\Model\Condition\Step\CouldSkipByNoFiles\Category" description="Check files to import."/>
        </conditions>
        <arguments>
            <argument key="command" value="import:categories" />
            <argument key="operation" value="add-update" />
        </arguments>
    </step>
    ...
</pipeline>
Virtualization of the Catalog Import vendor/techdivision/pacemaker-import-catalog/etc/di.xml condition
<virtualType name="TechDivision\PacemakerImportCatalog\Virtual\Model\Condition\Step\CouldSkipByNoFiles\Category" type="TechDivision\PacemakerImportBase\Model\Condition\Step\CouldSkipByNoFiles">
    <arguments>
        <argument name="getFileNamePattern" xsi:type="object">
            TechDivision\PacemakerImportCatalog\Virtual\ConfigProvider\GetFileNamePattern
        </argument>
    </arguments>
</virtualType>
  • Instead of the above virtualization and using a config provider, the FilePattern could be set directly

Virtualization Condition for Category Import with direct specification FilePattern
<virtualType name="TechDivision\PacemakerImportCatalog\Virtual\Model\Condition\Step\CouldSkipByNoFiles\Category">
    <arguments>
        <argument name="filePattern" xsi:type="string">
            <![CDATA[/category-import_([0-9a-z\-]*)([_0-9]*?).csv/i]]>
        </argument>
    </arguments>
</virtualType>

NoConflictingStepsInProcess

NoConflictingStepsInProcess is a generic step condition to check if steps got enqueued or in execution.

  • The steps for testing can get passed with parameters as an array

  • The variations can be defined with DI virtualizations

Virtualization of the Catalog Import vendor/techdivision/pacemaker-import-catalog/etc/di.xml condition
<virtualType name="TechDivision\PacemakerImportCatalog\Virtual\Condition\NoConflictingStepInProcess" type="TechDivision\PacemakerImportBase\Model\Condition\Step\NoConflictingStepsInProcess">
    <arguments>
        <argument name="stepNames" xsi:type="array">
            <item name="attribute_set_import" xsi:type="string">
                attribute_set_import
            </item>
            <item name="attribute_import" xsi:type="string">attribute_import</item>.
            <item name="category_import" xsi:type="string">category_import</item>.
            <item name="product_import" xsi:type="string">product_import</item>
        </argument>
    </arguments>
</virtualType>

IsStageReady

The IsStageReady condition is not used in the current scope of functions.

This is useful to combine several different steps as a so-called stage within a pipeline and to wait for their successful execution.

This logic is also useful if the steps in the pipeline logic can be processed in parallel and, for example, the last step may not be executed until all others before it have been completed, regardless of their order.