diff --git a/client/jobs.go b/client/jobs.go index 7899d3c4..9c541fd9 100644 --- a/client/jobs.go +++ b/client/jobs.go @@ -160,9 +160,6 @@ func (c *GRPCClient) ScheduleJobAlpha1(ctx context.Context, job *Job) error { if job.Name == "" { return errors.New("job name is required") } - if job.Data == nil { - return errors.New("job data is required") - } jobRequest := &runtimepb.Job{ Name: job.Name, diff --git a/workflow/context.go b/workflow/context.go index 7c293514..67071a75 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 b40ba4c8..a0bfd09e 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 + } +} diff --git a/workflow/workflow_test.go b/workflow/workflow_test.go index 3def77cb..983b8622 100644 --- a/workflow/workflow_test.go +++ b/workflow/workflow_test.go @@ -5,6 +5,7 @@ import ( "time" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/dapr/durabletask-go/api/protos" "github.com/dapr/durabletask-go/task" @@ -76,3 +77,21 @@ func TestNewTaskSlice(t *testing.T) { tasks := NewTaskSlice(10) assert.Len(t, tasks, 10) } + +func TestCreateTimerOptions(t *testing.T) { + t.Run("create timer options - valid", func(t *testing.T) { + opts := returnCreateTimerOptions(WithTimerName("test")) + require.NotNil(t, opts.name) + require.Equal(t, "test", *opts.name) + }) +} + +func returnCreateTimerOptions(opts ...createTimerOption) createTimerOptions { + options := new(createTimerOptions) + for _, configure := range opts { + if err := configure(options); err != nil { + return *options + } + } + return *options +}