Scheduling tasks in MODX

Run resource intensive processes in the background.

How to set it up

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 /var/www/romanesco/nursery/assets/components/scheduler/run.php

IMPORTANT

Make sure you add the cron job with the same user as PHP! Otherwise, the cron job will rip your installation to shreds by rewriting everything it touches with the wrong permissions. Yes, I found this out the hard way.

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.

IMPORTANT

Make sure the total duration of all the executed tasks doesn't overshoot the one minute until the next cronjob is triggered. Otherwise, you'll accumulate a backlog of pending tasks that will eventually cripple your server (again).