Running Scheduled Events with Docksal

Sean Dietrich
Docksal Maintainers Blog
2 min readDec 12, 2018

--

Did you know that Docksal comes with Cron built in? I can hear the muttering now….

But why would I need to run Cron on my local development?

That is a wonderful question. It’s because sometimes when we develop we want to make sure that our scheduled events are running properly. Think about it, of course they work perfectly when we run them manually. When we are running the process manually things seem to happen properly and seem to work as expected, but when we require that cron run them properly, they don’t always run smoothly.

How Do I Set Up Cron?

Another wonderful question. Well to do that, you would want to make sure there is a crontab file located within the .docksal/services/cli directory. The easy way to do this would be to run the following from your project directory:

mkdir -p .docksal/services/cli
touch .docksal/services/cli/crontab

This will create a new blank file in your project where you can start adding cron entries.

Anatomy of A Cron File

A crontab file has six fields for specifying minute, hour, day of month, month, day of week, and the command to be run at that interval. See below:

*     *     *     *     *  command to be executed 
- - - - -
| | | | |
| | | | +----- day of week (0 - 6) (Sunday=0)
| | | +------- month (1 - 12)
| | +--------- day of month (1 - 31)
| +----------- hour (0 - 23)
+------------- min (0 - 59)

So if setting up Drupal to run cron hourly using Drush, you could add the following into your project:

0 * * * * bash -lc 'drush --root=/var/www/web core:cron &>>/tmp/drupal-cron.log'

Interested in learning more about the cron feature? Head over to the Docksal Docs where you can learn more about cron and other features.

--

--