Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run individual cron jobs with Drush

Is it possible to run individual cron jobs via Drush? e.g. I have a cron job named "mycron". In the Esysia UI I can run that 1 job by clicking [run].

In drush, I can use the command "drush elysia-cron" but that will run all active cron jobs.

My Question: how can I run mycron (only) via drush?

Request: Make all cron jobs available in drush so "drush elysia-cron mycron" would work.

like image 511
Kathorey Ashly Avatar asked Oct 28 '14 08:10

Kathorey Ashly


People also ask

Is Drush a command line?

Drush, aka The Drupal Shell, is a command line utility and UNIX scripting interface for Drupal. It allows access to common Drupal features and tasks via the command line. It can help speed up common tasks for Drupal site builders, developers, and DevOps teams.


1 Answers

Here's how I am eval'ing my own cron hook.

1) Find the appropriate hook_cron call in your module. modulename_cron is what you want.

2) Figure out if any specific variables impact when it is run. In my case, there is a variable modulename_cron_last which tracks the last time the cron was run. I have to force this to 0 to get it to run.

3) Run drush:

drush eval "variable_set('modulename_cron_last', 0);"
drush eval "modulename_cron();"
drush eval "variable_set('modulename_cron_last', time());"

OR

If you use the 2.x DEV version for D7 this is possibile with command:

drush elysia-cron run [JOB_NAME]
or:
drush elysia-cron run [JOB_NAME] --ignore-time

(use --ignore-time to force execution)

4) Make a script and add it to your scheduler (in my case, the actual local Linux crontab)

like image 115
Mudassar Ali Sahil Avatar answered Sep 25 '22 05:09

Mudassar Ali Sahil