Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove jobs no longer referenced in the codebase #38693

Open
wants to merge 1 commit into
base: 2.4-develop
Choose a base branch
from

Conversation

fredden
Copy link
Member

@fredden fredden commented May 2, 2024

Description

When upgrading a Magento website over time, some cron jobs are left in the cron_schedule table for jobs which no longer exist. This can happen when a module is removed, or when a module removes a cronjob, or when a module changes the name of one of its cronjobs.

This pull request adds a daily clean-up task to remove such jobs from the schedule. This means that left-over jobs are pruned safely and the database table does have useless data.

Manual testing scenarios

  1. Run the Magento cron so that sitemap_generate gets scheduled. This belongs to the Magento_Sitemap module.
  2. Disable the Magento_Sitemap module.
  3. Run the Magento cron.
  4. Observe that there is (or not) a left-over entry for sitemap_generate in the cron_schedule database table.

Related issues

Fixes #38217

Contribution checklist

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • README.md files for modified modules are updated and included in the pull request if any README.md predefined sections require an update
  • All automated tests passed successfully (all builds are green)

Copy link

m2-assistant bot commented May 2, 2024

Hi @fredden. Thank you for your contribution!
Here are some useful tips on how you can test your changes using Magento test environment.

Add the comment under your pull request to deploy test or vanilla Magento instance:
  • @magento give me test instance - deploy test instance based on PR changes
  • @magento give me 2.4-develop instance - deploy vanilla Magento instance

❗ Automated tests can be triggered manually with an appropriate comment:

  • @magento run all tests - run or re-run all required tests against the PR changes
  • @magento run <test-build(s)> - run or re-run specific test build(s)
    For example: @magento run Unit Tests

<test-build(s)> is a comma-separated list of build names.

Allowed build names are:
  1. Database Compare
  2. Functional Tests CE
  3. Functional Tests EE
  4. Functional Tests B2B
  5. Integration Tests
  6. Magento Health Index
  7. Sample Data Tests CE
  8. Sample Data Tests EE
  9. Sample Data Tests B2B
  10. Static Tests
  11. Unit Tests
  12. WebAPI Tests
  13. Semantic Version Checker

You can find more information about the builds here
ℹ️ Run only required test builds during development. Run all test builds before sending your pull request for review.


For more details, review the Code Contributions documentation.
Join Magento Community Engineering Slack and ask your questions in #github channel.

@m2-github-services m2-github-services added Partner: Youwe partners-contribution Pull Request is created by Magento Partner labels May 2, 2024
@fredden
Copy link
Member Author

fredden commented May 2, 2024

@magento run all tests

@hostep
Copy link
Contributor

hostep commented May 3, 2024

Nice! Good job!

@fredden: can you add #38217 to the description of this PR? As this fixes that issue, so it automatically gets closed when this PR is merged.

I made the argument in there that maybe we should add the cleanup of unknown jobs to the Recurring setup script that exists in the Cron module, so it only does the cleanup when bin/magento setup:upgrade is being executed. Because disabling modules, or removing cronjobs, also requires bin/magento setup:upgrade to be ran.
That way, we don't need to check this daily. But I'm also fine with the daily cronjob like you implemented it now. It was just a thought.

@fredden
Copy link
Member Author

fredden commented May 3, 2024

add #38217 to the description of this PR? As this fixes that issue

Yes, I'll update this later today. Thanks for highlighting; I hadn't seen that report before now.

maybe we should add the cleanup of unknown jobs to the Recurring setup script that exists in the Cron module

I considered this approach too. This would catch most of the scenarios where groups or jobs are removed. There are two (main) reasons why I went with a periodic clean-up instead.

If the clean-up is in the setup:... process, then it should clean up all orphaned entries, not just "old" orphaned entries. This means that we immediately lose history for these jobs. When removing a module forever, this is typically fine; sufficient backing up of data is part of good maintenance. When a module simply renames a cronjob however (eg, to fix a typo), then losing history prematurely isn't ideal. (I'm thinking about the "timeline" view of a certain cronjobmanager module.)

The other reason for the periodic clean-up, is that I have seen modules dynamically create jobs, which then never get cleaned up by Magento when that module's configuration changes.

@fredden fredden force-pushed the feature/remove-unreferenced-cron-jobs branch 2 times, most recently from c84b05d to 9dea263 Compare May 5, 2024 09:46
@fredden
Copy link
Member Author

fredden commented May 5, 2024

@magento run all tests

@engcom-Hotel engcom-Hotel added the Priority: P2 A defect with this priority could have functionality issues which are not to expectations. label May 7, 2024
@sinhaparul sinhaparul added the Project: Community Picked PRs upvoted by the community label May 21, 2024
@m2-community-project m2-community-project bot added this to Review in Progress in Community Dashboard May 21, 2024
@m2-community-project m2-community-project bot removed this from Review in Progress in Pull Requests Dashboard May 21, 2024
@engcom-Hotel engcom-Hotel self-requested a review May 22, 2024 06:03
@engcom-Hotel
Copy link
Contributor

@magento run all tests

@engcom-Hotel
Copy link
Contributor

@magento run Database Compare, Functional Tests B2B, Functional Tests CE, Functional Tests EE, Integration Tests, Unit Tests, WebAPI Tests

Copy link
Contributor

@engcom-Hotel engcom-Hotel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @fredden,

Thanks for the collaboration!

The changes looks good to me but it seems the Integration test has been failing due to changes. I request you to please check the same.

Thanks

@fredden
Copy link
Member Author

fredden commented May 22, 2024

@engcom-Hotel thanks for your note. I don't know why I added a circular reference here. I've removed it now.

@fredden
Copy link
Member Author

fredden commented May 22, 2024

@magento run all tests

@engcom-Hotel
Copy link
Contributor

@magento run Functional Tests B2B, Functional Tests EE, Functional Tests CE, WebAPI Tests

@engcom-Hotel engcom-Hotel moved this from Changes Requested to Review in Progress in Community Dashboard May 23, 2024
@fredden fredden force-pushed the feature/remove-unreferenced-cron-jobs branch from bd0a0c6 to 9ebddc6 Compare May 23, 2024 08:12
@fredden
Copy link
Member Author

fredden commented May 23, 2024

I don't know why I added a circular reference here. I've removed it now.

I've worked out that this was a typing error. I had intended to add a dependency on Magento_Config. I've adjusted the commits here to reflect this.

@fredden
Copy link
Member Author

fredden commented May 23, 2024

@magento run all tests

Copy link
Contributor

@engcom-Hotel engcom-Hotel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Failed tests seems flaky to me.

@m2-community-project m2-community-project bot moved this from Review in Progress to Ready for Testing in Community Dashboard May 23, 2024
@engcom-Bravo engcom-Bravo self-assigned this May 24, 2024
@engcom-Bravo engcom-Bravo moved this from Ready for Testing to Testing in Progress in Community Dashboard May 24, 2024
@engcom-Bravo
Copy link
Contributor

Hi @fredden,

Thanks for the collaboration & contribution!

✔️ QA Passed

Preconditions:

  • Install fresh Magento 2.4-develop

Steps to reproduce

As per the Description.

Before: ✖️ 

Screenshot 2024-05-24 at 12 29 38

After: ✔️  

The Jobs for Disabled Modules are removed from the cron_schedule table from the database.

Builds are failed. Hence, moving this PR to Extended Testing.

Thanks.

@engcom-Bravo engcom-Bravo moved this from Testing in Progress to Extended testing (optional) in Community Dashboard May 24, 2024
@engcom-Echo engcom-Echo self-assigned this May 24, 2024
@m2-community-project m2-community-project bot moved this from Extended testing (optional) to Ready for Testing in Community Dashboard May 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Partner: Youwe partners-contribution Pull Request is created by Magento Partner Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Progress: ready for testing Project: Community Picked PRs upvoted by the community
Projects
Community Dashboard
Ready for Testing
Development

Successfully merging this pull request may close these issues.

Cleanup of cron_schedule database table doesn't cleanup non-existing jobs
8 participants