Skip to content

Commit

Permalink
Use correct time for initial schedule memo (#4128)
Browse files Browse the repository at this point in the history
  • Loading branch information
dnr authored Mar 31, 2023
1 parent fec04d1 commit c97c973
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion service/frontend/workflow_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -4969,7 +4969,7 @@ func (wh *WorkflowHandler) cleanScheduleMemo(memo *commonpb.Memo) *commonpb.Memo

// This mutates request (but idempotent so safe for retries)
func (wh *WorkflowHandler) addInitialScheduleMemo(request *workflowservice.CreateScheduleRequest, args *schedspb.StartScheduleArgs) {
info := scheduler.GetListInfoFromStartArgs(args)
info := scheduler.GetListInfoFromStartArgs(args, time.Now().UTC())
infoBytes, err := info.Marshal()
if err != nil {
wh.logger.Error("encoding initial schedule memo failed", tag.Error(err))
Expand Down
3 changes: 2 additions & 1 deletion service/worker/scheduler/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -1012,13 +1012,14 @@ func panicIfErr(err error) {
}
}

func GetListInfoFromStartArgs(args *schedspb.StartScheduleArgs) *schedpb.ScheduleListInfo {
func GetListInfoFromStartArgs(args *schedspb.StartScheduleArgs, now time.Time) *schedpb.ScheduleListInfo {
// note that this does not take into account InitialPatch
fakeScheduler := &scheduler{
StartScheduleArgs: *args,
tweakables: currentTweakablePolicies,
}
fakeScheduler.ensureFields()
fakeScheduler.compileSpec()
fakeScheduler.State.LastProcessedTime = timestamp.TimePtr(now)
return fakeScheduler.getListInfo()
}
3 changes: 3 additions & 0 deletions tests/schedule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,8 @@ func (s *scheduleIntegrationSuite) TestListBeforeRun() {
RequestId: uuid.New(),
}

startTime := time.Now()

_, err := s.engine.CreateSchedule(NewContext(), req)
s.NoError(err)

Expand All @@ -714,6 +716,7 @@ func (s *scheduleIntegrationSuite) TestListBeforeRun() {
s.Equal(wt, entry.Info.WorkflowType.Name)
s.False(entry.Info.Paused)
s.Greater(len(entry.Info.FutureActionTimes), 1)
s.True(entry.Info.FutureActionTimes[0].After(startTime))
return true
}, 10*time.Second, 1*time.Second)

Expand Down

0 comments on commit c97c973

Please sign in to comment.