Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
Cron execution is tricky in Drupal, as it can fail for multiple reasons:
- One particular
hook_cron()
requires too long, so its stuck somewhere - One particular function() fatals
The first step is always to figure out, which hook_cron() implementation is the problematic one, which can be hard in the first described case,
and not easy when your logs don't show backtraces in the second case.
Proposed resolution
Add logging for which cron implementation we started.
Suggested text:
<catch> dawehner: 'Starting execution of foo_cron(), execution of bar_cron() took 100ms' sort of thing?
Remaining tasks
User interface changes
API changes
Data model changes
Comment | File | Size | Author |
---|---|---|---|
#25 | drupal-cron_logging-2716073-25.patch | 1.32 KB | moonray |
#23 | drupal-cron_logging-2716073-23.patch | 578 bytes | moonray |
#17 | drupal-cron_logging-2716073-17.patch | 3.37 KB | moonray |
#14 | drupal-cron_logging-2716073-14.patch | 3.42 KB | moonray |
#11 | drupal-cron_logging-2716073-11.patch | 2.65 KB | moonray |
Comments
Comment #2
dawehnerComment #3
dawehnerComment #4
moonray CreditAttribution: moonray at Chapter Three commentedPlease review attached patch. It adds the necessary logging to cron in the above mentioned format.
Comment #6
moonray CreditAttribution: moonray at Chapter Three commentedIt looks like a logs related test needs tweaking.
Comment #7
dawehnerWell yeah we need to tweak
\Drupal\dblog\Tests\DbLogTest::verifyCron
to expect one additional log entry per module, which we should get from the module handler.Comment #8
moonray CreditAttribution: moonray at Chapter Three commentedThis patch updates the tests.
Comment #10
dawehnerIt seems to be the case that the patch files created by phpstorm are garbage. I would just recommend using
git diff > foo.patch
Comment #11
moonray CreditAttribution: moonray at Chapter Three commentedIndeed. Re-upping patch.
Comment #12
moonray CreditAttribution: moonray at Chapter Three commentedComment #14
moonray CreditAttribution: moonray at Chapter Three commentedThe log count never seems to add up properly, because some of the oldest log entries get removed.
I changed the log check to look at the newest watchdog log ID, and then after processing compare the watchdog ID against the previously recorded one.
Comment #15
dagmarNice! But do we need that $this->verbose()... ?
Comment #16
moonray CreditAttribution: moonray at Chapter Three commentedI guess that verbose is only useful for debugging. It can be removed.
Comment #17
moonray CreditAttribution: moonray at Chapter Three commentedRemoved excess verbose logging.
Comment #18
dawehnerNice work @moonray!
Comment #19
alexpottCommitted ffcbce2 and pushed to 8.2.x. Thanks!
Comment #20
alexpottComment #22
dawehnerThis patch could be backported to d7.
@moonray Do you want to try it out?
Comment #23
moonray CreditAttribution: moonray at Chapter Three commentedHere is actually a follow-up patch. We never output the duration of the last module that ran hook_cron.
I've got the D7 patch ready to go as well, but I'll post that once we get past the D8 follow-up.
Comment #25
moonray CreditAttribution: moonray at Chapter Three commentedIt would help if I actually included the updated test.
Comment #26
dawehnerGood catch!
Comment #27
alexpottCommitted 60d994a and pushed to 8.2.x. Thanks!
As per the new backport policy D7 patches should be their own issue.
Comment #29
moonray CreditAttribution: moonray at Chapter Three commentedD7 ticket is at #2722453: [D7] Improve cron logging