Question

I don't understand how scheduled import processes are starting.

I don't find a matching cronjob in Magento_ScheduledImportExport, only a cleaning job:

<job name="magento_scheduled_import_export_log_clean" instance="Magento\ScheduledImportExport\Cron\ScheduledLogClean" method="execute" />

Weirdly, the only thing I found that seems to take care of scheduled imports is a call to processScheduledOperation() in the controller Magento\ScheduledImportExport\Controller\Adminhtml\Scheduled\Operation\Cron:

/** @var \Magento\ScheduledImportExport\Model\Observer $result */
$result = $this->_objectManager->get(\Magento\ScheduledImportExport\Model\Observer::class)
                ->processScheduledOperation($schedule, true);

But I can't find a place where this controller would be called automatically.

Any idea?

Was it helpful?

Solution

I found it.

The job_code is scheduled_operation_ID with ID being the ID of the profile you created in the backend.

I did not have time to find how the job is added to the cron_schedule table but I know it's first added as a setting in the core_config_data table by _addCronTask() when the import profile is saved in the backend:

Magento\ScheduledImportExport\Model\Scheduled\Operation::_addCronTask()
mysql> select * from core_config_data where path like '%scheduled_operation_%';
+-----------+---------+----------+---------------------------------------------------------------+-------------------------------------------------------------------------+
| config_id | scope   | scope_id | path                                                          | value                                                                   |
+-----------+---------+----------+---------------------------------------------------------------+-------------------------------------------------------------------------+
|      1004 | default |        0 | crontab/default/jobs/scheduled_operation_1/schedule/cron_expr | 40 18 * * *                                                             |
|      1005 | default |        0 | crontab/default/jobs/scheduled_operation_1/run/model          | Magento\ScheduledImportExport\Model\Observer::processScheduledOperation |
+-----------+---------+----------+---------------------------------------------------------------+-------------------------------------------------------------------------+

Once saved as a setting (and the config cache emptied!), some other process detects it and add the new job in the cron_schedule table.

As a side note, the cronjob is set in the default group, which checks for new jobs only once every 15 minutes. Which means that setting a new import profile to run 5 minutes from now would never work. You either have to update the "refresh rate" of the group in System > Advanced > System > Cron (Scheduled Tasks) to 1 minutes or simply set your profile to run 15+ minutes later.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top