-
Notifications
You must be signed in to change notification settings - Fork 639
refactor!: Refactor cronjob controller to reduce duplication #3421
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
Conversation
| * @param params - The parameters for the background event. | ||
| * @returns The schedule parameters for the background event. | ||
| */ | ||
| function getStartDate(params: ScheduleBackgroundEventParams) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic for scheduling was previously done in snaps-rpc-methods, but handling this from the cronjob controller is easier to reduce duplication.
| "jobs": [ | ||
| { | ||
| "expression": "*/10 * * * * *", | ||
| "expression": "PT10S", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to find a way to test both formats 😓
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Likely easiest with a new example Snap. Just changed it here for local testing purposes.
794289e to
8951701
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #3421 +/- ##
==========================================
+ Coverage 98.16% 98.18% +0.01%
==========================================
Files 402 399 -3
Lines 11141 11127 -14
Branches 1750 1750
==========================================
- Hits 10937 10925 -12
+ Misses 204 202 -2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
79d4de2 to
c16a656
Compare
|
@Mrtenz Can you add a note about the breaking changes in the description please? |
The cronjob controller contained a lot of essentially duplicated logic after the addition of background events. To resolve this, I've refactored the cronjob controller to treat cronjobs as recurring background events. This means:
lastRunproperty in favour of adateproperty. We can now simply check if the current date is past the scheduled date to know if a cronjob should be executed immediately.In addition to these changes, I've made some smaller changes to the controller like replacing TypeScript's
privatemodifier with true hash private functions.Breaking changes
jobsstate property was removed, cronjobs are now stored in theeventsproperty as well.CronjobController:schedulenow expects aschedulefield instead ofdate.BackgroundEventsuffix.CronjobController:scheduleBackgroundEvent->CronjobController:scheduleCronjobController:cancelBackgroundEvent->CronjobController:cancel.CronjobController:getBackgroundEvents->CronjobController:get.