CLI Job / Cron Runner

Скачать CLI Job / Cron Runner
Сейчас ищут:

Itnull

Команда форума
Администратор
Регистрация
22.05.13
Сообщения
25.109
Реакции
9.054
Веб-сайт
itnull.me
  • Автор темы
  • Администратор
  • Модер.
  • Команда форума
  • #1
Compatible XF Versions2.2 , 2.3

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 called hg:run-jobs and does the same thing that xf:run-jobs does, but with more options and functionality.

Features

Main features of this addon:
  • 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
Requirements

This addon requires PHP 7.0 or higher and has been tested on XenForo 2.2.0 beta 1

Installation

Install as per normal addon installation.

1721480163372.png


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:

Both options (crontab and cron.d) will execute the job runner every minute, checking for outstanding jobs to be run.

By default, the job runner will run for a maximum of 30 seconds, executing any outstanding jobs until there are no more runnable jobs in the queue.

Configuration

You may adjust the maximum execution time of the job runner by specifying the --time=[TIME] option on the command line.


For example, to allow the job runner to execute for a maximum of 45 seconds:


Bash:
$ php <path to your forum root>/cmd.php --time=45 hg:run-jobs
This addon uses lock files to prevent multiple job runner commands to execute at the same time, which also allows us to have the command run for longer periods on busy sites.

The maximum execution time allowed is 10 minutes (600 seconds). The command will execute until it finds no more outstanding jobs and then stop - so execution time is typically only a few seconds.


For further customisation of your job execution, you may also adjust the maximum time that each job is permitted to run.
This is configured via a XenForo config.php Option:



PHP:
$config['jobMaxRunTime'] = 8;
The jobMaxRunTime option configures the amount of time in seconds that processing jobs will be allowed to run before they are suspended for further processing on another go-around, if possible. The default setting is optimised for the browser-triggered job runner and so to allow jobs to execute longer in a CLI environment, you may want to adjust this to a higher value.

In general it is suggested that this setting be kept to a relatively small value to avoid the situation where a single very long job may prevent other jobs from executing in a timely manner. Some experimentation may be required to find the optimal value for your server load and forum size. If in doubt, leave it as the default setting of 8 seconds.

Usage

The run-jobs command should be executed automatically using a cron task as per the instructions above.

Show Jobs

The hg:show-jobs command outputs a list of all the currently pending jobs, so you can see how full the jobs queue is.

By default only the next scheduled 100 jobs will be shown, you may use the --all option to show a complete list of all pending jobs.

There should always be at least one job (the main Cron job) in the list. For XF 2.1 and above you will also see the upgrade check job.


Bash:
$ php cmd.php xf:show-jobs

2 pending jobs found

+----------------+-----------------+----------------------+----------------------+
| Key | Class | Next Run | Last Run |
+----------------+-----------------+----------------------+----------------------+
| cron | XF\Job\Cron | 11-Apr-2019 10:52:01 | 11-Apr-2019 10:52:31 |
| xfUpgradeCheck | XF:UpgradeCheck | 12-Apr-2019 00:12:21 | 10-Apr-2019 21:24:03 |
+----------------+-----------------+----------------------+----------------------+

The current time is: 11-Apr-2019 10:52:31 (UTC+10:00)
Debugging Jobs

There are extensive debugging tools to help identify issues with Jobs and Cron tasks.

To run in debug mode, first disable the Unix cron which runs jobs automatically (don't forget to turn it back on again once you are finished debugging!) and then use the verbosity options (Verbose: -v, Very verbose: -vv or Debug: -vvv) for the hg:run-jobs command to specify the level of output to show on the console.

Output is to the console and is in a format similar to that used by the Monolog library (although we do not use Monolog to generate the output).

For example, Verbose option -v:

CLI Job / Cron Runner 2.1.1
 
Назад
Сверху Снизу