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

isDue() not working properly #161

Open
Morgunov-Vitaly opened this issue Aug 10, 2023 · 2 comments
Open

isDue() not working properly #161

Morgunov-Vitaly opened this issue Aug 10, 2023 · 2 comments

Comments

@Morgunov-Vitaly
Copy link

$cron = new CronExpression($cronExpression); $cron->isDue($currentTime)
isDue() is not working as expected - on one of the servers it returns false. But when I'm testing it in a local environment returns true. $currentTime is the same as system datatime. It seems that it may be related with NTP server configuration issues.

@dragonmantank
Copy link
Owner

Can you elaborate any further? At the end of the day all the library does is compare an expression against a timestamp (either the passed time, or the current system time) and tell you if that time is in the expression's limit.

When it fails, is $currentTime the same value on all the machines just one server fails?

Can you also let me know what expression you are using, a sample time you are using that fails, what OS is failing, and which version of the library you are using?

@shaneparsons
Copy link

shaneparsons commented Oct 25, 2023

May be a separate issue than OP, but I'm seemingly having issues w/ isDue / getNextRunDate so I figured I'd post here.

Here's are logs of mine that illustrate the problem:

Logs
[2023-10-25T18:40:34.916030+00:00] app.DEBUG: Current time 2023-10-25 14:40:34 [] []
[2023-10-25T18:40:34.916414+00:00] app.DEBUG: Cron is not due. [] []
[2023-10-25T18:40:34.916656+00:00] app.DEBUG: Cron should have last run at 2023-10-25 15:59:00 [] []
[2023-10-25T18:40:34.916825+00:00] app.DEBUG: Cron will next run at 2023-10-26 15:00:00 [] []

Here's the code that generates that log:

Code
private const CRON_SCHEDULE = '* 15 * * *';
private const TIME_ZONE = 'America/New_York';

$cron = new CronExpression(self::CRON_SCHEDULE);
$this->logger->debug(
    sprintf(
        'Current time %s',
        (new DateTime('now'))->setTimezone(new DateTimeZone(self::TIME_ZONE))->format('Y-m-d H:i:s')
    )
);
if (!$cron->isDue('now', self::TIME_ZONE)) {
    $this->logger->debug('Cron is not due.');
    $this->logger->debug(
        sprintf(
            'Cron should have last run at %s',
            $cron->getPreviousRunDate()->format('Y-m-d H:i:s')
        )
    );
    $this->logger->debug(
        sprintf(
            'Cron will next run at %s',
            $cron->getNextRunDate()->format('Y-m-d H:i:s')
        )
    );
    return;
}

Since the current time is 14:40, and the run time is 15:00, I would have expected that getNextRunDate would have returned 2023-10-25 rather than 2023-10-26.

I've been poking around for some time now but haven't been to determine why this is behaving the way it is. Will update this post if I make any headway, but would appreciate any ideas in the meantime.

I'm running v3.3.3 FYI. Let me know if you need any other details.


Update:

Just determined that the getPreviousRunDate / getNextRunDate logs were incorrect because I wasn't running them with the allowCurrentDate / timeZone params. When running with those params those parts do work as intended. Will keep looking, but the issue may be on my side after all.

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

3 participants