-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Fix for missed cronjobs history cleanup #1052
Fix for missed cronjobs history cleanup #1052
Conversation
Hi, @LukeOl The scheduler in Magento 2 marks jobs as "Missed" in case if the time in "ScheduledAt" field had already passed and it happened more than "Missed if Not Run Within" minutes ago. If job marked as "Missed" it can only mean that execution of the job failed. All the jobs marked as "Missed" will never run again and should be deleted after waiting for "Failure History Lifetime" minutes. Looking into Observer class I see that it marks job as “Missed” but never put proper value to executed_at field, so that later job will be deleted immediately, instead of waiting for the time configured for keeping the history. Am I correctly understand the issue? The problem which I see with the fix is that Observer will wait needed amount of minutes since job was created, not since job was failed. If "Missed if Not Run Within” is long enough in comparison with "Failure History Lifetime” then admin will never get a chance to see the jobs marked as “Missed”. It will be better to update the executed_at field with the current timestamp whenever job status is changed to “missed” or “error”. Does this makes sense? Are you willing to do this change? Also, I would suggest to add tests to highlight the issue. It is something we ask contributors to do as a part of https://github.com/magento/magento2/wiki/Contribution-Guide Tracking number MAGETWO-34526 |
Hello, @vrann Yes, you understand issue correctly. But I don't think filling execution_at field with current timestamp is correct solution.
That I proposed my way to solve this issue. About tests: what exactly do you need (unit, other, ?)? Only for this case or overall for Cron? (because I haven't found any tests related to cron yet - if it exists please point my where it are). Thx for your answer & greetings. |
Hi, @LukeOl, you are right, it is valid concern. However I think it is responsibility of the UI to display this data in the way that is not confusing. For example it may call it “date when it was marked as missed” and it will be clear what it means. Regardless of that, solution should take into account the time that passed before job was marked as missed. Otherwise this “history lifetime” configuration will be confusing (and this is what I was hoping to fix). Just as an example, it may be changed to something like $checkTime = $record->getScheduledAt()) + $timeWaitingForMissed; Regarding tests, please take a look at Magento\Cron\Model\ObserverTest::testDispatchCleanup() in the dev/tests/unit/testsuite, it looks like you would need to add another case to test there and design it in the same way as other tests in this class. Definitely let me know if you cannot make changes now and I will take care of that. This PR is already valuable regardless of will you do any further work on it. Thanks! |
@LukeOl this change was covered with the tests in the internal codebase. We will merge this PR soon. Thanks! |
Hi @vrann Sorry for not giving sign of life. I was workloaded and I was unable to answer you, sorry for this. I am glad of your message about merging my change :) If there is something about the case, which might be help to you guys, fell free to ask me! I will try give faster feedback since last attempt :) Thanks! |
Fix for missed cronjobs history cleanup
@LukeOl, this has now been published in 0.74.0-beta1. Thank you again for your valuable contribution and for your continued support in Magento! We greatly appreciate it! |
…omer mutation #1052 - Merge Pull Request magento/graphql-ce#1052 from magento/graphql-ce:createCustomer-remove-redundant-logic - Merged commits: 1. 3a7ae91
This is Magento 1 legacy code, so the same issue exists in Magento 1.
Magento clean up mechanism for scheduled cronjobs has two options:
Success job is the one with status Success.
Failure job is the one with statuses Missed or Error.
Unfortunately, when Magento cleans up job's history, the script will clean jobs with status Missed, ignoring option "Clean success/failure history after some seconds".
Scheduled cronjobs with status Missed do not have executed time field filled. So Missed cronjob will be erased besides of Clean success/failure history after some seconds option.
I propose to use "ScheduledAt" time (because it is always filled when schedule is generated) if job was not executed ("ExecutedAt" field is empty).
Testing scenario for this case: