Skip to content

workflows: support timer names #729

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.23.6

require (
github.com/dapr/dapr v1.15.0-rc.17
github.com/dapr/durabletask-go v0.6.3
github.com/dapr/durabletask-go v0.7.1
github.com/go-chi/chi/v5 v5.1.0
github.com/golang/mock v1.6.0
github.com/google/uuid v1.6.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK3
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
github.com/dapr/dapr v1.15.0-rc.17 h1:bR0rd4FH81IteuOHTWVNyl58ZuQTDp3DYaTtXnpZ6JA=
github.com/dapr/dapr v1.15.0-rc.17/go.mod h1:SD0AXom2XpX7pr8eYlbJ+gHfNREsflsrzCR19AZJ7/Q=
github.com/dapr/durabletask-go v0.6.3 h1:WHhSAw1YL4xneK3Jo5nGfmMaJxfFodIIF5q1rpkDDfs=
github.com/dapr/durabletask-go v0.6.3/go.mod h1:nTZ5fCbJLnZbVdi6Z2YxdDF1OgQZL3LroogGuetrwuA=
github.com/dapr/durabletask-go v0.7.1 h1:FiTlVVFh0UnYdqoFeUtgT7BszkGMA0eL0qjgfB7YOr0=
github.com/dapr/durabletask-go v0.7.1/go.mod h1:JhMyDybRUFmmgieGxCPeg9e2cWwtx4LwNXjD+LBtKYk=
github.com/dapr/kit v0.15.0 h1:446jrEOQV/0rt6FwmoKrifP3vav5+Uh/u38DqU8q+JM=
github.com/dapr/kit v0.15.0/go.mod h1:HwFsBKEbcyLanWlDZE7u/jnaDCD/tU+n3pkFNUctQNw=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down
11 changes: 10 additions & 1 deletion workflow/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,16 @@
// The value passed to the Await method must be a pointer or can be nil to ignore the returned value.
// Alternatively, tasks can be awaited using the task.WhenAll or task.WhenAny methods, allowing the workflow
// to block and wait for multiple tasks at the same time.
func (wfc *WorkflowContext) CreateTimer(duration time.Duration) task.Task {
func (wfc *WorkflowContext) CreateTimer(duration time.Duration, opts ...createTimerOption) task.Task {
options := new(createTimerOptions)
for _, configure := range opts {
if err := configure(options); err != nil {
return nil
}

Check warning on line 102 in workflow/context.go

View check run for this annotation

Codecov / codecov/patch

workflow/context.go#L97-L102

Added lines #L97 - L102 were not covered by tests
}
if options.name != nil {
return wfc.orchestrationContext.CreateTimer(duration, task.WithTimerName(*options.name))
}

Check warning on line 106 in workflow/context.go

View check run for this annotation

Codecov / codecov/patch

workflow/context.go#L104-L106

Added lines #L104 - L106 were not covered by tests
return wfc.orchestrationContext.CreateTimer(duration)
}

Expand Down
13 changes: 13 additions & 0 deletions workflow/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,16 @@
taskSlice := make([]task.Task, length)
return taskSlice
}

type createTimerOption func(*createTimerOptions) error

type createTimerOptions struct {
name *string
}

func WithTimerName(name string) createTimerOption {
return func(opt *createTimerOptions) error {
opt.name = &name
return nil
}

Check warning on line 162 in workflow/workflow.go

View check run for this annotation

Codecov / codecov/patch

workflow/workflow.go#L158-L162

Added lines #L158 - L162 were not covered by tests
}