-
Notifications
You must be signed in to change notification settings - Fork 0
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(scheduler): change to single task based scheduler #235
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #235 +/- ##
==========================================
- Coverage 71.57% 71.35% -0.23%
==========================================
Files 33 33
Lines 3536 3501 -35
Branches 420 413 -7
==========================================
- Hits 2531 2498 -33
- Misses 848 849 +1
+ Partials 157 154 -3
|
|
||
// If the next occurrence is less or equal than the current UTC time (plus tolerance) | ||
// and is greater than the last run time, trigger the simulation run. | ||
if (nextOccurrence <= DateTime.UtcNow.Add(tolerance) && nextOccurrence > lastRun) |
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.
if (nextOccurrence <= DateTime.UtcNow.Add(tolerance) && nextOccurrence > lastRun) | |
if (nextOccurrence >= DateTime.UtcNow && nextOccurrence <= DateTime.UtcNow.Add(tolerance) && nextOccurrence > lastRun) |
otherwise it might fire before the actual schedule (we can't allow that)
@@ -43,50 +42,25 @@ public async Task Delay(TimeSpan delay, CancellationToken token) | |||
|
|||
/// <summary> | |||
/// Represents a scheduled job for simulation. | |||
/// (No longer used since scheduling is now done in a single loop.) |
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.
why are you keeping it then?
// to a new configuration on the API | ||
if (scheduledJobs.TryGetValue(routineRev.RoutineExternalId, out var job)) | ||
// Parse the cron schedule. | ||
CrontabSchedule schedule; |
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.
maybe put this into the map as well, so we don't recompute it each time?
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.
could probably repurpose ScheduledJob
for this
Current scheduler has a dotnet
Task
for each routine revision. This leads to problems when a large number of RoutineRevisions are scheduled at the exact same time every hour. This PR changes the approach so we dont create Tasks at all, rather have just oneTask
that keeps waking up every minute and goes through all the routines in the state to decide which needs to be scheduled based on their cron expression.