0

If cron_job() is my function running the cron job

function cron_job(){
     // I would like to get the current job_id or the cron schedule model here
}

Is there any way to retrieve this data in Magento version > 1.9

Fabian Schmengler
  • 65,791
  • 25
  • 187
  • 421
  • 1
    Please be a bit more clear with your question. Providing an actual function example and an explanation of what you hope to achieve would help. – scrowler Jun 22 '16 at 07:34
  • 1
    @MagenX how is this a duplicate? It doesn't mention the scheduler anywhere – scrowler Jun 22 '16 at 08:13

1 Answers1

3

The cronjob methods can take a Mage_Cron_Model_Schedule parameter which contains the job metadata (you can even change it).

Example:

function cron_job(Mage_Cron_Model_Schedule $schedule)
{
    $id = $schedule->getId(); // ID in `cron_schedule` database table
    $jobCode = $schedule->getJobCode();
    $status = $schedule->getStatus(); // will be "running" obviously
    $messages = $schedule->getMessages();
    $createdAt = $schedule->getCreatedAt();
    $scheduledAt = $schedule->getScheduledAt();
    $executedAt = $schedule->getExecutedAt(); 
    $finishedAt = $schedule->getFinishedAt(); // will be empty since the job is not finished yet
}
Fabian Schmengler
  • 65,791
  • 25
  • 187
  • 421