Scheduling tasks in MODX

Run resource intensive processes in sequence, in the background.

Start by installing Scheduler via package management (ModMore provider).

Configure it to run every minute, via cron job:

crontab -e

Then add the following line at the bottom:

* * * * * php -q /home/hugo/Localhost/romanesco/nursery/assets/components/scheduler/run.php

That's it! Now you can add resource intensive tasks like generating critical CSS to the Scheduler queue.

Adjusting tasks per run

By default, Scheduler will only run 1 task every minute (I think). You can tweak this by adding a system setting scheduler.tasks_per_run with a different value. Multiple tasks will be triggered on each run then.

Try to avoid that the duration of the triggered tasks overshoots the one minute until the next task is run. Otherwise, you might accumulate a backlog of pending tasks that will eventually cripple your server (again).