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

scheduling not working on a specified date #63

Closed
Oguntoye opened this issue Sep 4, 2018 · 1 comment
Closed

scheduling not working on a specified date #63

Oguntoye opened this issue Sep 4, 2018 · 1 comment

Comments

@Oguntoye
Copy link

Oguntoye commented Sep 4, 2018

I couldn't get a script run at a specified date..
This is my code... it is not executing at the date specified it is rather executing instantly.. please help me.

$datetorun = new DateTime('2018-09-04 18:48:00');
$scheduler = new Scheduler();
$scheduler->php($pathtophpscripttorun, '/usr/local/bin/php')->run($datetorun);

what am i doing run.. please help.. i want the skip to run at the date specified.

@peppeocchi
Copy link
Owner

@Oguntoye by passing the date to the run method you're effectively faking the current time in the system. The job has no specified time to run so it's assumed it should run every minute.
To give you an example, the above code is registering a new job to run every minute, then when the scheduler gets executed it's assuming the current date is 2018-09-04 18:48:00 instead of the actual now date, so every time the scheduler runs it will always run as it was that date/time.

Passing the date to the run method is primarily used to facilitate testing of the scheduler (you can find more details here #28 (comment))

Instead, if you want to run your script at a specific date and time, you might do so by using a cron expression, so your code will look like

$scheduler = new Scheduler();
$scheduler->php($pathtophpscripttorun, '/usr/local/bin/php')->at('48 18 4 9 *');
$scheduler->run();

Just a note, that will execute the script every year on that date and time (cron don't have support for the year), another workaround would be to add a condition before scheduling the job. Example of pseudocode below

$scheduler = new Scheduler();

$datetorun = new DateTime('2018-09-04 18:48:00');
if ($datetorun === now) {
    $scheduler->php($pathtophpscripttorun, '/usr/local/bin/php');
}

$scheduler->run();

This would be a great feature to build into the scheduler. I'll add to the list for the next release.

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

2 participants