Skip to content
chris edited this page Feb 27, 2021 · 2 revisions

After a successful installation, you can access to this URL:

http://{your-app-root}/command-scheduler/list.

From this screen, you can do following actions :

  • Create a new scheduling
  • Edit an existing scheduling
  • Enable or disable scheduling (by clicking the "Power Off/On" switch)
  • Manually execute a command (It will be launched during the next scheduler:execute, regardless of the cron expression)
  • Unlock a task (if the lock is due to an unrecoverable error for example)

When creating a new scheduling, you can provide your commands arguments and options exactly as you wold do from the console. Remember to use quotes when using arguments and options that includes white spaces.

After that, you have to set (every few minutes, it depends of your needs) the following command in your system crontab :

$ php bin/console scheduler:execute --env=env -vvv [--dump] [--no-output]

If the --dump option is set, the scheduler won't execute any command, but just list commands that should be executed. Without the option, commands will be executed depending their priority and last execution time (highest priority will run first).

The --env= and -v (or --verbosity) arguments are passed to all scheduled command from scheduler:execute, so you don't have to put these on each scheduling !

If you don't want to have any message (except error) from scheduler itself you can use the --no-output option.

The scheduler:execute command will do following actions :

  • Get all scheduled commands in database (unlocked and enabled only)
  • Sort them by priority (desc)
  • Check if the command has to be executed at current time, based on its cron expression and on its last execution time
  • Execute eligible commands (without exec php function)

The scheduler:unlock command is capable of unlock all or a single scheduled command with a lock-timeout parameter. It can be usefull if you don't have a full control about server restarting, which can a command in a lock state.

Deamon (Beta) : If you don't want to set up a cron job, you can use scheduler:start and scheduler:stop commands.
This commands manage a deamon process that will call scheduler:execute every minute. It require the pcntlphp extension.
Note that with this mode, if a command with an error, it will stop all the scheduler.

Note : Each command is locked just before his execution (and unlocked after). This system avoid to have simultaneous process for the same command. Thus, if an non-catchable error occurs, the command won't be executed again unless the problem is solved and the task is unlocked manually.

Monitoring

To enable (external) checks if the jobs are running correctly there is a URL which runs a check with the following requirements/limits:

  • only check enabled commands
  • return value not equal 0 means there is something wrong
  • running jobs can be checked for a maximum runtime

To run the check simply call

http://{your-app-root}/command-scheduler/monitor

The call returns a JSON object with either HTTP 200 and an empty array (everything ok) or HTTP 417 (Expectation failed) and an object containing all the (failed) jobs with name, last execution time, locked state and return code.

For "internal" monitoring of jobs there is also a command "scheduler:monitor" which does the same check as the monitor call before except it sends emails to an arbitrary number of receivers (if the server allows sending mails with the "mail" command). As some kind of "self-monitoring" job the monitor command can be configured to send emails to all receivers if everything's ok - if there is no mail at all a problem occured.

For any comments, questions, or bug report, use the Github issue tracker.

Clone this wiki locally