Skip to content

Commit 0bb9dc3

Browse files
Use the same timer duration validation with server (#1121)
1 parent 7c70757 commit 0bb9dc3

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

internal/internal_event_handlers.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -551,26 +551,29 @@ func (wc *workflowEnvironmentImpl) Now() time.Time {
551551
}
552552

553553
func (wc *workflowEnvironmentImpl) NewTimer(d time.Duration, callback resultHandler) *timerInfo {
554-
if d < 0 {
555-
callback(nil, fmt.Errorf("negative duration provided %v", d))
554+
durationInSeconds := common.Int64Ceil(d.Seconds())
555+
if durationInSeconds < 0 {
556+
callback(nil, fmt.Errorf("negative duration provided %v", durationInSeconds))
556557
return nil
557558
}
558-
if d == 0 {
559+
if durationInSeconds == 0 {
559560
callback(nil, nil)
560561
return nil
561562
}
562563

563564
timerID := wc.GenerateSequenceID()
564565
startTimerAttr := &m.StartTimerDecisionAttributes{}
565566
startTimerAttr.TimerId = common.StringPtr(timerID)
566-
startTimerAttr.StartToFireTimeoutSeconds = common.Int64Ptr(common.Int64Ceil(d.Seconds()))
567+
startTimerAttr.StartToFireTimeoutSeconds = common.Int64Ptr(durationInSeconds)
567568

568569
decision := wc.decisionsHelper.startTimer(startTimerAttr)
569570
decision.setData(&scheduledTimer{callback: callback})
570571

571572
wc.logger.Debug("NewTimer",
572573
zap.String(tagTimerID, startTimerAttr.GetTimerId()),
573-
zap.Duration("Duration", d))
574+
zap.Duration("Duration", d),
575+
zap.Int64("DurationInSeconds", durationInSeconds),
576+
)
574577

575578
return &timerInfo{timerID: timerID}
576579
}

0 commit comments

Comments
 (0)