Skip to content

Commit

Permalink
IWF-158: Keeping compatibility for NewTimerCommand(firingTime)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevo89519 committed Oct 2, 2024
1 parent cf96435 commit 48510cf
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
2 changes: 1 addition & 1 deletion integ/signal_workflow_state2.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func (b signalWorkflowState2) WaitUntil(ctx iwf.WorkflowContext, input iwf.Objec
},
iwf.NewSignalCommand(signalCommandId, testChannelName1),
iwf.NewSignalCommand(signalCommandId, testChannelName2),
iwf.NewTimerCommand(timerCommandId, int64(time.Duration(24)*time.Hour/time.Second)),
iwf.NewTimerCommandByDuration(timerCommandId, 24*time.Hour),
), nil
}

Expand Down
5 changes: 3 additions & 2 deletions integ/timer_workflow_state1.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package integ

import (
"github.com/indeedeng/iwf-golang-sdk/iwf"
"time"
)

type timerWorkflowState1 struct {
Expand All @@ -10,10 +11,10 @@ type timerWorkflowState1 struct {
}

func (b timerWorkflowState1) WaitUntil(ctx iwf.WorkflowContext, input iwf.Object, persistence iwf.Persistence, communication iwf.Communication) (*iwf.CommandRequest, error) {
var i int64
var i int
input.Get(&i)
return iwf.AllCommandsCompletedRequest(
iwf.NewTimerCommand("", i),
iwf.NewTimerCommandByDuration("", time.Duration(i)*time.Second),
), nil
}

Expand Down
19 changes: 18 additions & 1 deletion iwf/command.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package iwf

import "time"

type (
CommandType string

Expand Down Expand Up @@ -50,7 +52,12 @@ func NewInternalChannelCommand(commandId, channelName string) Command {
}
}

func NewTimerCommand(commandId string, durationSeconds int64) Command {
func NewTimerCommand(commandId string, firingTime time.Time) Command {
durationSeconds := int64(firingTime.Sub(time.Now()).Seconds())

Check failure on line 56 in iwf/command.go

View workflow job for this annotation

GitHub Actions / golangci

[golangci] iwf/command.go#L56

S1024: should use time.Until instead of t.Sub(time.Now()) (gosimple)
Raw output
iwf/command.go:56:27: S1024: should use time.Until instead of t.Sub(time.Now()) (gosimple)
	durationSeconds := int64(firingTime.Sub(time.Now()).Seconds())
	                         ^
if durationSeconds < 0 {
panic("Firing time is set in the past")
}

return Command{
CommandId: commandId,
CommandType: CommandTypeTimer,
Expand All @@ -59,3 +66,13 @@ func NewTimerCommand(commandId string, durationSeconds int64) Command {
},
}
}

func NewTimerCommandByDuration(commandId string, durationSeconds time.Duration) Command {
return Command{
CommandId: commandId,
CommandType: CommandTypeTimer,
TimerCommand: &TimerCommand{
DurationSeconds: int64(durationSeconds.Seconds()),
},
}
}

0 comments on commit 48510cf

Please sign in to comment.