CLI Job Runner for XF 2.1

CLI Job Runner for XF 2.1 1.5.0

No permission to download
Just out of curiosity.

My current time is 12:48AM, and noticed that the next cron job is 21-Feb-2020 00:02:43. (14min).

I assume if I go to the cron entries on XF, the timestamps on the nextrun is still in sync with CLI Job Runner. If that's the case, it shows the next job is at 12:50AM. (through the admincp).

Checked it in the past few hours, and the next run that shows on php cmd.php xf:show-jobs always seems to appear to be 10 to 15min later. While I do have jobs that runs every minute.

Is this normal?

My current set-up:

Code:
* * * * * php xxxxxxxxxxxxxx/cmd.php --quiet --time=300 xf:run-jobs
 
Can you paste the output of your xf:show-jobs command here, including the "current time" message at the bottom, so I can see what's happening?

Mine shows the expected output:

Code:
$ xf xf:show-jobs

3 pending jobs found

+----------------+-----------------+----------------------+----------------------+
| Key            | Class           | Next Run             | Last Run             |
+----------------+-----------------+----------------------+----------------------+
| cron           | XF\Job\Cron     | 21-Feb-2020 10:54:01 | 21-Feb-2020 10:54:31 |
| xfUpgradeCheck | XF:UpgradeCheck | 22-Feb-2020 02:46:02 | 20-Feb-2020 20:19:03 |
| xfCollectStats | XF:CollectStats | 05-Mar-2020 16:25:50 | 04-Feb-2020 09:39:02 |
+----------------+-----------------+----------------------+----------------------+

The current time is: 21-Feb-2020 10:54:57 (UTC+11:00)
 
Sure thing:

Code:
php cmd.php xf:show-jobs

2 pending jobs found

+----------------+-----------------+----------------------+----------------------+
| Key            | Class           | Next Run             | Last Run             |
+----------------+-----------------+----------------------+----------------------+
| cron           | XF\Job\Cron     | 21-Feb-2020 00:09:01 | 20-Feb-2020 23:54:01 |
| xfUpgradeCheck | XF:UpgradeCheck | 21-Feb-2020 23:46:05 | 20-Feb-2020 17:50:02 |
+----------------+-----------------+----------------------+----------------------+

The current time is: 20-Feb-2020 23:57:44 (UTC+00:00)
 
That is a bit strange. Are you sure you have XenForo cron tasks currently enabled which run every minute?

The cron system will set the job "next run" time to be what ever time the next cron task is scheduled to run at - so if that's 15 minutes from now, that's when the next trigger of the cron job will be.

However, if you have cron tasks that run every minute, then the cron system should be setting the next run time to around a minute from now. This is what mine is doing.
 
... and now it says next run 11:05 - I'll take another look at the code to see if I can work out why it's misreporting the next run time.
 
Thanks :). The only thing I can think of why mine is way off constantly is because a discord add-on takes up a few minutes (and running per minute) to complete.

But a lot of cron entries timestamps through the admincp show a much sooner run time. Hence I found it odd.
 
I'm finding that it will come up saying next run time is 15 minutes from now, but then if I run it again immediately afterwards, it's back to the correct time.

Looking through the code in XF\Job\Manager::runJobEntry, I'm pretty sure this is the expected behaviour.

From what I can tell, the system starts by updating the job and setting the trigger date to 15 minutes into the future - presumably to stop it being triggered again by a different process while it runs the job.

Next, it runs the job.

If the job is marked complete, the job is then deleted from the database.

If the job is marked resume (like the cron task is), then it will update the job entry with the next trigger date.

So I believe what we are seeing is that time period between the job being triggered (and updated to 15 minutes next run time) and then being set to resume (and updated to 1 minute next run time).

In your case, because your task is taking more than a minute to execute, the next run time is almost never shows as being in a minute's time because it's still in the temporary "15 minutes from now just in case" state until the cron finishes and resets.

So I consider this to be normal behaviour.
 
This addon will not work on XF 2.2 due to a name clash with the new Server based trigger CLI command.

I will be releasing a new version of the addon that is compatible with XF 2.2 but uses a different CLI command name.
 
This addon will not work on XF 2.2 due to a name clash with the new Server based trigger CLI command.
While not explicitly required by resource standards rule # 25, I think it is a good practice to always prefix custom commands :)
 
Sim updated CLI Job Runner with a new update entry:

v1.4.0: Major update for XF v2.1

I've back-ported the new CLI Job Runner and debugger I built for XF v2.2 (which is a drop-in replacement for the built in xf:run-jobs command that comes with XF2.2).

THIS IS A MAJOR UPDATE - THERE ARE STEPS YOU MUST TAKE AFTER UPGRADING TO USE THIS NEW VERSION - SEE UPGRADE INSTRUCTIONS BELOW.

THIS VERSION IS NOT COMPATIBLE WITH XF v2.2
- please use the version available here: https://xenforo.com/community/resources/cli-job-runner-for-xf-2-2.7931/...
Read the rest of this update entry...
 
Just a note on Upgrading to XenForo v2.2:

Versions 1.3 and 1.4 of this addon are not compatible with XenForo v2.2 - after upgrading XenForo you will need to upgrade to v2.0 of the Job Runner addon - available here: https://xenforo.com/community/resources/cli-job-runner-for-xf-2-2.7931/

Note that you could also choose to simply remove this addon and use the built-in xf:run-jobs command supplied in the XF v2.2 core - it does the same thing, but with less advanced functionality than this addon.
 
Sim updated CLI Job Runner with a new update entry:

v1.5.0 update

v1.5.0 makes some back-end changes to the way we manage the lock files and fixes an issue where long running jobs could see multiple job runners executing at the same time
  • code cleanup: we don't need a custom app class to show jobs
  • new CLI command: hg:show-crons
  • new CLI command: hg:run-cron
  • add logQuiet function to LoggerTrait
  • rebuilt Lock functionality to use a non-static class, managed by a SubContainer
  • ensure lock expiry is at least 30 seconds after the max...

Read the rest of this update entry...
 
Great addon, thank you @Sim!

Just to be safe: Will errors (like mysql table locks) still be saved to XF's error log? We are running the cron with --quiet option.
 
Great addon, thank you @Sim!

Just to be safe: Will errors (like mysql table locks) still be saved to XF's error log? We are running the cron with --quiet option.

The Job Runner boots the XenForo framework to execute the jobs - so yes, anything that would normally be logged to the Error log will do so, even with the quiet option turned on.

The quiet option simply prevents cli output from showing in the console - which on some unix systems will be emailed to the administrator when run from cron.
 
Thank you for your support!

This addon helped a lot on a large high traffic forum to prevent mysql table locks (because of simultaneously executed jobs, that blocked each other).
 
I am not in the office, cant get on the server now.
I have an cron job and the cli runner.

I have disabled the cron-job, but it is still running.

So probably this comes from my crontab.

Is there a way to decide run/not run from the acp in xf?

Or just disable the cli-runner?

---------------
could solve with commented line in crontab

but it would be nice to trigger it from the acp (with mobile from everywhere)
 
Last edited:
Top Bottom