-
Notifications
You must be signed in to change notification settings - Fork 591
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
*/ | ||
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.
@@ -20,7 +20,7 @@ | |||
"endowment:cronjob": { | |||
"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:
lastRun
property in favour of adate
property. 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
private
modifier with true hash private functions.Breaking changes
jobs
state property was removed, cronjobs are now stored in theevents
property as well.CronjobController:schedule
now expects aschedule
field instead ofdate
.BackgroundEvent
suffix.CronjobController:scheduleBackgroundEvent
->CronjobController:schedule
CronjobController:cancelBackgroundEvent
->CronjobController:cancel
.CronjobController:getBackgroundEvents
->CronjobController:get
.