Skip to content

Cleanup of cron_schedule database table doesn't cleanup non-existing jobs #38217

@hostep

Description

@hostep

Preconditions and environment

  • Magento version 2.4.6-p3 (but most likely all versions will be affected)

Steps to reproduce

Explanation below how to trigger this with a cronjob from inside core Magento. But the most likely cases will come from 3rd party modules containing cronjobs, that were installed for a while and then removed again.

  1. Have a Magento shop with MSI modules enabled
  2. Have a working crontab and have it running for a couple of hours
  3. Inspect the cron_schedule table and notice that the job inventory_in_store_pickup_sales_send_order_notified_emails is mentioned many times with status success
  4. Now, disable all MSI modules in app/etc/config.php and run bin/magento setup:upgrade
  5. Keep the crontab running for a few more hours
  6. Inspect your cron_schedule table again

Expected result

It's expected that all jobs that were successful and having run more than 60 minutes ago are removed from the cron_schedule table.

Actual result

See that there are still jobs inventory_in_store_pickup_sales_send_order_notified_emails in the table with status success and being older then 60 minutes. Those don't get cleaned up because the MSI modules are no longer active and calling getJobs() over here doesn't return jobs from inactive (or removed) modules.

Additional information

Ideally, the cronjob cleanup should also figure out which jobs are in the cron_schedule table that are no longer found in the system and clean those up as well.
Or maybe this can be added in the existing Recurring data script that exists in the Magento_Cron module, as then it doesn't need to be checked every minute when the cron actually runs. Since removing and disabling modules requires a bin/magento setup:upgrade call anyway, it might be a good idea to only then check for outdated entries in that table and remove them...

And since the cron_schedule table receives a lot of queries the entire day, it's beneficial to performance that it contains as few rows as possible. Old data should be cleaned up automatically.

I found this in a shop where we have hundreds of entries from 2021 in the cron_schedule table for jobs that for a long time no longer existed.

Release note

No response

Triage and priority

  • Severity: S0 - Affects critical data or functionality and leaves users without workaround.
  • Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
  • Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
  • Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
  • Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.

Metadata

Metadata

Labels

Area: CatalogComponent: CronIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedPriority: P2A defect with this priority could have functionality issues which are not to expectations.Progress: doneReported on 2.4.6-p3Indicates original Magento version for the Issue report.Reproduced on 2.4.xThe issue has been reproduced on latest 2.4-develop branch

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions