This XenForo 2.2 addon implements an advanced CLI triggered job runner for use with Unix cron as a replacement for the built-in xf:run-jobs command introduced in XF 2.2
The command is calledhg:run-jobs and does the same thing thatxf:run-jobs does, but with more options and functionality.
Features
Main features of this addon:xf:run-jobshg:run-jobsxf:run-jobs
allows commands to process jobs/crons for up to 10 minutes at a time, even when triggered every minute from a cron task (uses a lock file to prevent multiple executions in parallel) - ideal for improving job performance on high traffic sites
extensive debugging output available for testing and identifying issues with jobs and cron tasks
drop-in replacement for xf:run-jobs
command to list all outstanding Jobs hg:show-jobs
command to list all XF Cron tasks hg:show-crons
command to execute an XF Cron task hg:run-cron
Requirements
This addon requires PHP 7.0 or higher and has been tested on XenForo 2.2.0
Installation
Install as per normal addon installation.
Once installed, go to the System and performance options page as change the Job run trigger setting to "Server based trigger"
First, you should test that your job runner is functioning - execute the following command from your CLI:
Bash:
$ php <path to your forum root>/cmd.php hg:run-jobs
For example, if your forum root is/srv/www/xenforo/community, then the job runner command would be:
Running this command will execute any outstanding jobs and then finish with a message about whether there are more jobs waiting to be executed or not. When executing this command from cron, it is recommended that you use the--quiet (or -q) flag to suppress output.
Once you are happy that the job runner functions correctly, you will need to create your own cron task to run it on a schedule of your choosing.
Once you are happy that the job runner functions correctly, you will need to create your own cron task to run it on a schedule of your choosing.
NOTE: if you already have a cron task set up to run xf:run-jobs simply disable that and replace it with an identical task which runs hg:run-jobs instead.
Approach #1 using crontab:
It is highly recommended that you have your cron task run as the web server user to prevent potential permission problems.
For example, on Ubuntu with a web server user of www-data, install a cron task by running the following command: