Problem/Motivation
It is often useful to prevent cron from being run at the Drupal-level (as opposed to the OS-level in the case of a crontab being used, for example).
Use Case 1:
When deploying code from a staging environment to a production environment, it can be desirable to disable cron on the production environment prior to the deployment then re-enable it after the deployment. In some cases, it is undesirable to enable maintenance mode to achieve this.
Use Case 2:
When copying the database from a production environment to a staging environment, it can be desirable to ensure that cron jobs running on the production environment have time to complete before the database is copied (and that those jobs don't start again until the database has finished being copied). This prevents the staging environment from thinking that cron jobs are already running when in fact they started on the production environment, not the staging environment.
Proposed resolution
Introduce a new a variable "ultimate_cron_disable_scheduled", which (when equal to 1 or TRUE) prevents all jobs from running as scheduled (whether cron is executed via Drush, Drupal's external-facing cron URL, or via the UI).
This variable can be set using Drush (e.g. "drush vset ultimate_cron_disable_scheduled 1" / "drush vset ultimate_cron_disable_scheduled 0") and/or overridden in settings.php (e.g. on a per-environment basis).
A named job can still be run via the UI or via "drush cron-run JOB_NAME".
Remaining tasks
Document this variable in the module's documentation.
User interface changes
None required. This variable could optionally be exposed as a setting to allow enabling/disabling scheduled cron via the UI.
API changes
None.
Data model changes
None.
Original report by [sinn]
I know that we can disable cron execution if we use poorman cron.
But how can we disable cron execution if cron is executed from outside? This case is useful when we deploy new code on a site or site is in maintenance mode.
Comment | File | Size | Author |
---|---|---|---|
#10 | ultimate_cron-disable_scheduled_cron_variable-2632340-10.patch | 2.79 KB | arnested |
Comments
Comment #2
arnested CreditAttribution: arnested at Reload commentedThe jobs will not be launched when the site is in maintenance mode.
Comment #3
sinn CreditAttribution: sinn commentedThey will be.
Comment #4
arnested CreditAttribution: arnested at Reload commentedHmm...
Running scheduled jobs should be disabled during maintenance_mode: http://cgit.drupalcode.org/ultimate_cron/tree/ultimate_cron.module#n1581
But runnig named jobs is not disabled.
And you have a point that it might also be an idea to just have a "disable all cron execution" option that can be set no whether you are in maintenance mode or not.
Comment #5
sinn CreditAttribution: sinn commentedWhat is difference between named jobs and scheduled jobs?
All my cron jobs (that is described in hook_cron or hook_cron_queue_info) are executed in maintenance mode.
Comment #6
RedEight CreditAttribution: RedEight at 95Visual commentedI think what he is saying is that Ultimate Cron will actually stop any cron job from running when the site is in maintenance mode... I'm currently fighting this issue as I have a number of cron jobs that DO need to run in maintenance mode but Ultimate Cron is blocking them.
Comment #7
jdleonardComment #9
jdleonardOoops; looks like testing is disabled for D7 and I accidentally set that patch to be tested for D8. Please ignore the test failure.
Comment #10
arnested CreditAttribution: arnested at Reload commentedThank you for your patch, jdleonard!
I have add some minor improvements:
* In
hook_uninstall()
delete the variable before clearing the variable cache.* Avoid nesting if's in
ultimate_cron_run_scheduled()
by using early returns instead.* Add checks to
hook_requirements()
so we will show on the status page if scheduled jobs will not be run because they have been disabled or we are in maintenance mode.There is one thing that remains problematic, though.
If cron is launched via wget og curl on
/cron.php the new variable will not have any effect.
Comment #11
jdleonardGreat additions, thanks arnested!
I tested your patch and everything is working as expected for me, including cron not being run via wget on cron.php (I received the expected message "Cannot launch scheduled jobs while ultimate_cron_disable_scheduled variable is set!"). Can you confirm that wget on cron.php is unexpectedly running cron when ultimate_cron_disable_scheduled is set to a non-zero value?
Assuming things are working for you, I think this is RTBC with the possible exception of some documentation.
Comment #13
arnested CreditAttribution: arnested at Reload commentedIndeed it works with cron.php as well. Wonder what I was doing when testing it - probably too tired.
I have committed the patch and released a new version 7.x-2.5.
I'm going to close this issue now knowing it does not solve all wishes mentioned in the issue (RedEights need for enabling/disabling individual jobs during maintenance mode). Please open a new issue if those needs still exist.
Comment #15
delacosta456 CreditAttribution: delacosta456 commentedhi
is it still possible to use this functionality with 8 version?