-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Skip over entire time range if paused and batch and cache time queries #4215
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
Changes from all commits
39036c3
d8e6383
5782384
0bfb2f2
13793a4
ee96872
4165936
584d190
a861b9f
46b85b7
f5d4291
f9eae8f
230541a
f268b46
b4051e8
27b66cb
b7ac461
6bb79ac
732bf0f
199ba33
191d03a
9521321
6eb8d75
26a76df
790dc4b
3fd344a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,6 +27,7 @@ package scheduler | |
| import ( | ||
| "context" | ||
| "errors" | ||
| "math/rand" | ||
| "testing" | ||
| "time" | ||
|
|
||
|
|
@@ -1402,3 +1403,74 @@ func (s *workflowSuite) TestLimitedActions() { | |
| s.True(s.env.IsWorkflowCompleted()) | ||
| // doesn't end properly since it sleeps forever after pausing | ||
| } | ||
|
|
||
| func (s *workflowSuite) TestLotsOfIterations() { | ||
| // This is mostly testing getNextTime caching logic. | ||
| const runIterations = 30 | ||
| const backfillIterations = 15 | ||
|
|
||
| runs := make([]workflowRun, runIterations) | ||
| for i := range runs { | ||
| t := time.Date(2022, 6, 1, i, 27+i%2, 0, 0, time.UTC) | ||
| runs[i] = workflowRun{ | ||
| id: "myid-" + t.Format(time.RFC3339), | ||
| start: t, | ||
| end: t.Add(time.Duration(5+i%7) * time.Minute), | ||
| result: enumspb.WORKFLOW_EXECUTION_STATUS_COMPLETED, | ||
| } | ||
| } | ||
|
|
||
| delayedCallbacks := make([]delayedCallback, backfillIterations) | ||
|
|
||
| expected := runIterations | ||
| // schedule a call back every hour to spray backfills among scheduled runs | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. one nitpick: can you make the backfill only start after 2022-06-01 15:00:00? i.e. I want at least one long stretch where the cache runs out and has to refill naturally. (or even better, use the value of |
||
| // each call back adds random number of backfills in | ||
| // [maxNextTimeResultCacheSize, 2*maxNextTimeResultCacheSize) range | ||
| for i := range delayedCallbacks { | ||
|
|
||
| maxRuns := rand.Intn(maxNextTimeResultCacheSize) + maxNextTimeResultCacheSize | ||
| expected += maxRuns | ||
| // a point in time to send the callback request | ||
| callbackTime := time.Date(2022, 6, 1, i+15, 2, 0, 0, time.UTC) | ||
| // start time for callback request | ||
| callBackRangeStartTime := time.Date(2022, 5, i, 0, 0, 0, 0, time.UTC) | ||
|
|
||
| // add/process maxRuns schedules | ||
| for j := 0; j < maxRuns; j++ { | ||
| runStartTime := time.Date(2022, 5, i, j, 27+j%2, 0, 0, time.UTC) | ||
| runs = append(runs, workflowRun{ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm glad these don't have to be in order, that'd be even more annoying |
||
| id: "myid-" + runStartTime.Format(time.RFC3339), | ||
| start: callbackTime.Add(time.Duration(j) * time.Minute), | ||
| end: callbackTime.Add(time.Duration(j+1) * time.Minute), | ||
| result: enumspb.WORKFLOW_EXECUTION_STATUS_COMPLETED, | ||
| }) | ||
| } | ||
|
|
||
| delayedCallbacks[i] = delayedCallback{ | ||
| at: callbackTime, | ||
| f: func() { | ||
| s.env.SignalWorkflow(SignalNamePatch, &schedpb.SchedulePatch{ | ||
| BackfillRequest: []*schedpb.BackfillRequest{{ | ||
| StartTime: timestamp.TimePtr(callBackRangeStartTime), | ||
| EndTime: timestamp.TimePtr(callBackRangeStartTime.Add(time.Duration(maxRuns) * time.Hour)), | ||
| OverlapPolicy: enumspb.SCHEDULE_OVERLAP_POLICY_BUFFER_ALL, | ||
| }}, | ||
| }) | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| s.runAcrossContinue( | ||
| runs, | ||
| delayedCallbacks, | ||
| &schedpb.Schedule{ | ||
| Spec: &schedpb.ScheduleSpec{ | ||
| Calendar: []*schedpb.CalendarSpec{ | ||
| {Minute: "27", Hour: "0/2"}, | ||
| {Minute: "28", Hour: "1/2"}, | ||
| }, | ||
| }, | ||
| }, | ||
| expected+1, | ||
| ) | ||
| } | ||
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.
one more thing: I think that Get into a map may actually add entries instead of resetting the map (it ends up in the data converter which does json.Unmarshal), so the map might keep growing. I think we should explicitly clear the map before Get just in case
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.
good idea, will do.