How to pass custom arguments/parameters for cron jobs in Magento2.
I found an article related to this for Magento 1.x, I am trying to figure out how to do the same for Magento 2.x
How to pass custom arguments/parameters for cron jobs in Magento2.
I found an article related to this for Magento 1.x, I am trying to figure out how to do the same for Magento 2.x
Try to use \Magento\Cron\Model\Schedule
class as a parameter. And, use \Magento\Cron\Model\Config
to get the config. (Not yet test)
/**
* Cron job config
*
* @var \Magento\Cron\Model\Config
*/
protected $config;
public function __construct(
\Magento\Cron\Model\Config $config
) {
$this->config = $config;
}
public function execute(\Magento\Cron\Model\Schedule $schedule)
{
$jobsRoot = $this->config->getJobs()
....
}
If the first way cannot work, we should try to inject \Magento\Cron\Model\Schedule
on the constructor.
There is no "parameters" field in the cron_schedule table by default Magento. Refer How to pass parameters to Magento 2 crons