Elysia Cron without Elysia in Drupal 8

Sun, 01/24/2016 - 21:48 | 1143 Views

One of the most popular modules in Drupal worlds is Elysia Cron, because allow us to have a granular control over cron function execution process.

Therefore, the uncomfortable question nowadays is when we will have a version of Drupal 8 of Elysia Cron, because, for some websites this module is critical to publish a website in production.

I heard some people that say, due modules like Elysia are not ported yet to Drupal 8 yet, Drupal 8 couldn't be considered for production sites.

I totally disagree with that, and I will show you how to get the same level of granularity we got in the past with Elysia Cron, but without Elysia Cron.

To provide a solution I will use the Drupal Console project.

Drupal 8 core provide a way to run cron implementation accessing the URL http://example.com/ /cron/<hash>, you can get the full URL from Status report page https://example.com/admin/reports/status. But, this approach executes all cron implementation in sequence, and most of the times, that is a bad idea, due some implementations could take too much time in their execution and the last implementations are never executed.

Let me explain how cron command in Drupal Console works. Firstly, we have a command to list all cron implementations as you can see below

$ drupal cron:debug

Cron Debug

As you can imagine or suffer in the past search and node cron implementations could take forever if you have a big amount of content on your website, the image above is the output of a fresh Drupal 8 installation, you will get module contrib and module custom implementations in a regular website.

In order to execute all cron implementation you can use the command execute as you can see below

$ drupal cron:execute all

Cron execute all

Off course, this execution doesn't provide any change respect with the system cron execution but using a different set of options I can accomplish what I promise at the beginning of this article.

If we want to execute only one or more cron implementations we just need to replace all for required module implementation, let me show you an example.

$drupal cron:execute search update

Cron execute partial

Using this trick we can skip that cron implementation with problems of execution and just focus in what we need.

To automatize oue Drupal cron execution, we can implement a cron job. For Linux and mac users you can do setting in you cron something like this

45 * * * * /usr/local/bin/drupal cron:execute search 
30 * * * * / usr /local/bin/drupal  cron :execute node

If you are a windows user you can follow this guide Configuring cron jobs with Windows or use the service http://cronless.com/

I hope do you found this article useful.