From ca6e00ad25d707825c1ab5bcd336a9129294aaa8 Mon Sep 17 00:00:00 2001 From: Fabian Martinez <46371672+famarting@users.noreply.github.com> Date: Fri, 23 May 2025 13:32:06 +0200 Subject: [PATCH] workflows: support timer names Signed-off-by: Fabian Martinez <46371672+famarting@users.noreply.github.com> --- go.mod | 2 +- go.sum | 4 ++-- workflow/context.go | 11 ++++++++++- workflow/workflow.go | 13 +++++++++++++ 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index 2737a4f..f0ccb64 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 456920d..1b8374b 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/workflow/context.go b/workflow/context.go index 7c29351..67071a7 100644 --- a/workflow/context.go +++ b/workflow/context.go @@ -94,7 +94,16 @@ func (wfc *WorkflowContext) CallChildWorkflow(workflow interface{}, opts ...call // 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 + } + } + if options.name != nil { + return wfc.orchestrationContext.CreateTimer(duration, task.WithTimerName(*options.name)) + } return wfc.orchestrationContext.CreateTimer(duration) } diff --git a/workflow/workflow.go b/workflow/workflow.go index b40ba4c..a0bfd09 100644 --- a/workflow/workflow.go +++ b/workflow/workflow.go @@ -148,3 +148,16 @@ func NewTaskSlice(length int) []task.Task { 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 + } +}