To prevent conflict and performance problems with other code that runs during cron, decorate the cron service instead of implementing hook_cron

Created on 31 May 2023, over 1 year ago
Updated 1 June 2023, over 1 year ago

Problem/Motivation

Right now we implement hook_cron to run background updates

We have πŸ“Œ Disallow unattended updates if performed by automated_cron Fixed which will solve some problems but we some other problems with using cron.

  1. Code could run after our updates. We could use hook_implements_alters to make our hook run last but the way \Drupal\Core\Cron::run works is it will run all hook_cron implementations and then process the cron queue items.
  2. A lot of code could run before us which could lead to time outs. To solve 1) we could implement a cron queue item and make sure we run last but then all hook_cron implementations and other items in the queues would run before us. This could lead to time out issues

Steps to reproduce

Proposed resolution

  1. \Drupal\automatic_updates\CronUpdateStage should Decorate the cron service
  2. before call the decorate service it should see if there is update that needs to happen
  3. If an update is attempt it should not call the decorated cron service
  4. If no update is attempted it should call the decorated service

Once πŸ“Œ Disallow unattended updates if performed by automated_cron Fixed is fix then if someone hits the system/cron route then if there is an update that will be the only thing that happens during the cron run.

If cron is set to run every 3 hours and there is 2 core path updates a month(which would be very high) then that would me only 2 of the cron runs would be taken over by auto updates.

Remaining tasks

User interface changes

API changes

Data model changes

πŸ“Œ Task
Status

Needs work

Version

3.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States tedbow Ithaca, NY, USA

Live updates comments and jobs are added and updated live.
  • Performance

    It affects performance. It is often combined with the Needs profiling tag.

Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024