Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to schedule a job for immediate execution and trigger the cron to run asyncronously? #374

Open
Blatant opened this issue Apr 13, 2018 · 0 comments

Comments

@Blatant
Copy link

Blatant commented Apr 13, 2018

Here's the situation,

I have a scheduled job to generate a number of files and such becasue some can be time expensive. Basically a "create file/report" queue system.

It all works fine and is set to run every minute, every minute the queue of files is processed. however I have been asked if I can remove the waiting period (upto 59 seconds) on the first request without bypassing the lock and AOE's excellent management so that even when triggered straight away it will not ignore the job lock (if it happens to be running already via the generated_schedule it would not run).

This needs to run asyncronously, I realise I can runNow however as I read the code I beleive runNow() would run syncronously so the file creation job would need to complete before code continues from calling runNow().

I thought this must be possible by first scheduling a task for immediate execution (scheduled_at = time()) and then executing the scheduler_cron.sh script via shell_exec.

Enter code example :

    //schedule an immediate job
    $time = time();
    $schedule->setJobCode('my_action')
        ->setScheduledReason("My Actions Immediate Create Dispatch.")
        ->setStatus(Aoe_Scheduler_Model_Schedule::STATUS_PENDING)
        ->setCreatedAt(strftime('%Y-%m-%d %H:%M:%S', $time))
        ->setScheduledAt(strftime('%Y-%m-%d %H:%M:%S', $time))
         ->save();
    //fire the cron manager now just to reduce wait on first report
    if ( file_exists(Mage::getBaseDir().DS."scheduler_cron.sh") ){
        shell_exec("sh ".Mage::getBaseDir().DS."scheduler_cron.sh > /dev/null 2>/dev/null &");
    }

The above code works in that the job is scheduled correctly and the scheduler_cron.sh script does execute (I debugged this with a log file, the sh file is definatelly executing). However the immediately scheduled job does not run! Instead the schedule executes upto a minute later via cron and it marks my immediate job as missed ad executes the generated_schedule one, ergo no instant fire.

Can you advise how I might be able to schedule the action and execute it immediately without bypassing the mutex that AOE Scheduler uses?

Thanks in advance!

Danny Walker

@Blatant Blatant changed the title Is it possible to schedule a job for immendiate execution and trigger the cron to run asyncronously? Is it possible to schedule a job for immediate execution and trigger the cron to run asyncronously? Apr 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant