Ability to disable execution of scheduled jobs

Created on 10 December 2015, almost 9 years ago
Updated 6 April 2024, 8 months ago

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.

Feature request
Status

Fixed

Version

2.0

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024