XF\Job\Manager::hasStoppedJobs() does not work correctly outside of UTC timezone

nocte

Well-known member
Affected version
2.2.8 Patch 1
Here's the method:

PHP:
    public function hasStoppedJobs(): bool
    {
        $pending = $this->queuePending(false);

        if (!$pending)
        {
            return false;
        }

        $jobRunTime = $this->app['job.runTime'];
        if (!$jobRunTime)
        {
            return false;
        }

        if ($jobRunTime + 3600 <= \XF::$time)
        {
            // scheduled run time exceeded by an hour so jobs appear to be stuck
            return true;
        }
        else
        {
            return false;
        }
    }

If I am outside of UTC timezone, jobs won't run at the the time they are supposed to (I think this has already been discussed). So, if my timezone is UTC+2 and I set a job to run at 14 pm, it will actually run at 16 pm. For the above method this is 1 hours too late (if ($jobRunTime + 3600 <= \XF::$time)).

Result: If you have any jobs, that are more than 1 minute (not 1 hour as intended) too late, you will see this in your admin cp index:

Bildschirmfoto 2022-06-10 um 16.28.24.png

Disclaimer: did not look too much into the code, but I am quite sure, this is a bug as described. It matches my experience.

@Sim talked about the 1 minute delay as well: https://xenforo.com/community/threads/cli-job-cron-runner.183700/post-1563676
 

Sim

Well-known member
If I am outside of UTC timezone, jobs won't run at the the time they are supposed to (I think this has already been discussed). So, if my timezone is UTC+2 and I set a job to run at 14 pm, it will actually run at 16 pm. For the above method this is 1 hours too late (if ($jobRunTime + 3600 <= \XF::$time)).

The time you set in the cron task is in UTC.

The "next run" time you see in the cron entry list is in your personal time zone set in your profile.

So if you want to have a job run at 2pm your time and you are UTC+2, you need to set the cron task to run at 12pm. The "next run" time in the cron entry list should accurately reflect the time it will run in your local timezone.

Are you working on a development site, or a production site with low traffic? If you're using the "Activity based trigger" on a low traffic site, you can have difficulty with cron tasks running on schedule because there is no activity to trigger it. Using the "Server based trigger" (ie triggered by a system cron task) can help here.
 

nocte

Well-known member
The time you set in the cron task is in UTC.

The "next run" time you see in the cron entry list is in your personal time zone set in your profile.

So if you want to have a job run at 2pm your time and you are UTC+2, you need to set the cron task to run at 12pm. The "next run" time in the cron entry list should accurately reflect the time it will run in your local timezone.
That's clear to me.

Are you working on a development site, or a production site with low traffic? If you're using the "Activity based trigger" on a low traffic site, you can have difficulty with cron tasks running on schedule because there is no activity to trigger it. Using the "Server based trigger" (ie triggered by a system cron task) can help here.
I am talking about a high traffic site with "server based trigger", that uses your addon ;)

When I refresh the admin cp index over and over, most time I see the message about jobs not getting executed as expected, but sometimes for a few seconds I don't see it.

My point is (correct me, if I am wrong), that it seems, that the hasStoppedJobs() method is only working as intended, if the board's timezone is UTC.
 

nocte

Well-known member
I think this was false alarm and the bug report can be closed. Sorry for that.

I have indeed some troubles with the admin cp index showing me "outstanding jobs" (tough jobs are executed via server cron every minute), but I cannot replicate this issue on my local machine. Maybe there is a bug anywhere (XF or an addon), but I have to investigate further and don't think it's a timezone issue.
 
Top