Skip to content

Commit 8ab62d9

Browse files
Add schedule API (#943)
Add experimental schedule API
1 parent 620fa72 commit 8ab62d9

16 files changed

+2650
-6
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ default: check test
66
# general build-product folder, cleaned as part of `make clean`
77
BUILD := .build
88

9-
TEST_TIMEOUT := 3m
9+
TEST_TIMEOUT := 5m
1010
TEST_ARG ?= -race -v -timeout $(TEST_TIMEOUT)
1111

1212
INTEG_TEST_ROOT := ./test

client/client.go

+100
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,102 @@ type (
9191
// CheckHealthResponse is a response for Client.CheckHealth.
9292
CheckHealthResponse = internal.CheckHealthResponse
9393

94+
// ScheduleRange represents a set of integer values.
95+
// NOTE: Experimental
96+
ScheduleRange = internal.ScheduleRange
97+
98+
// ScheduleCalendarSpec is an event specification relative to the calendar.
99+
// NOTE: Experimental
100+
ScheduleCalendarSpec = internal.ScheduleCalendarSpec
101+
102+
// ScheduleIntervalSpec describes periods a schedules action should occur.
103+
// NOTE: Experimental
104+
ScheduleIntervalSpec = internal.ScheduleIntervalSpec
105+
106+
// ScheduleSpec describes when a schedules action should occur.
107+
// NOTE: Experimental
108+
ScheduleSpec = internal.ScheduleSpec
109+
110+
// ScheduleBackfill desribes a time periods and policy and takes Actions as if that time passed by right now, all at once.
111+
// NOTE: Experimental
112+
ScheduleBackfill = internal.ScheduleBackfill
113+
114+
// ScheduleAction is the interface for all actions a schedule can take.
115+
// NOTE: Experimental
116+
ScheduleAction = internal.ScheduleAction
117+
118+
// ScheduleWorkflowAction is the implementation of ScheduleAction to start a workflow.
119+
// NOTE: Experimental
120+
ScheduleWorkflowAction = internal.ScheduleWorkflowAction
121+
122+
// ScheduleOptions configuration parameters for creating a schedule.
123+
// NOTE: Experimental
124+
ScheduleOptions = internal.ScheduleOptions
125+
126+
// ScheduleClient is the interface with the server to create and get handles to schedules.
127+
// NOTE: Experimental
128+
ScheduleClient = internal.ScheduleClient
129+
130+
// ScheduleListOptions are configuration parameters for listing schedules.
131+
// NOTE: Experimental
132+
ScheduleListOptions = internal.ScheduleListOptions
133+
134+
// ScheduleListIterator is a iterator which can return created schedules.
135+
// NOTE: Experimental
136+
ScheduleListIterator = internal.ScheduleListIterator
137+
138+
// ScheduleListEntry is a result from ScheduleListEntry.
139+
// NOTE: Experimental
140+
ScheduleListEntry = internal.ScheduleListEntry
141+
142+
// ScheduleUpdateOptions are configuration parameters for updating a schedule.
143+
// NOTE: Experimental
144+
ScheduleUpdateOptions = internal.ScheduleUpdateOptions
145+
146+
// ScheduleHandle represents a created schedule.
147+
// NOTE: Experimental
148+
ScheduleHandle = internal.ScheduleHandle
149+
150+
// ScheduleActionResult describes when a schedule action took place.
151+
// NOTE: Experimental
152+
ScheduleActionResult = internal.ScheduleActionResult
153+
154+
// ScheduleWorkflowExecution contains details on a workflows execution stared by a schedule.
155+
// NOTE: Experimental
156+
ScheduleWorkflowExecution = internal.ScheduleWorkflowExecution
157+
158+
// ScheduleDescription describes the current Schedule details from ScheduleHandle.Describe.
159+
// NOTE: Experimental
160+
ScheduleDescription = internal.ScheduleDescription
161+
162+
// Schedule describes a created schedule.
163+
// NOTE: Experimental
164+
Schedule = internal.Schedule
165+
166+
// ScheduleUpdate describes the desired new schedule from ScheduleHandle.Update.
167+
// NOTE: Experimental
168+
ScheduleUpdate = internal.ScheduleUpdate
169+
170+
// ScheduleUpdateInput describes the current state of the schedule to be updated.
171+
// NOTE: Experimental
172+
ScheduleUpdateInput = internal.ScheduleUpdateInput
173+
174+
// ScheduleTriggerOptions configure the parameters for triggering a schedule.
175+
// NOTE: Experimental
176+
ScheduleTriggerOptions = internal.ScheduleTriggerOptions
177+
178+
// SchedulePauseOptions configure the parameters for pausing a schedule.
179+
// NOTE: Experimental
180+
SchedulePauseOptions = internal.SchedulePauseOptions
181+
182+
// ScheduleUnpauseOptions configure the parameters for unpausing a schedule.
183+
// NOTE: Experimental
184+
ScheduleUnpauseOptions = internal.ScheduleUnpauseOptions
185+
186+
// ScheduleBackfillOptions configure the parameters for backfilling a schedule.
187+
// NOTE: Experimental
188+
ScheduleBackfillOptions = internal.ScheduleBackfillOptions
189+
94190
// Client is the client for starting and getting information about a workflow executions as well as
95191
// completing activities asynchronously.
96192
Client interface {
@@ -389,6 +485,10 @@ type (
389485
// OperatorService creates a new operator service client with the same gRPC connection as this client.
390486
OperatorService() operatorservice.OperatorServiceClient
391487

488+
// Schedule creates a new shedule client with the same gRPC connection as this client.
489+
// NOTE: Experimental
490+
ScheduleClient() ScheduleClient
491+
392492
// Close client and clean up underlying resources.
393493
//
394494
// If this client was created via NewClientFromExisting or this client has

interceptor/interceptor.go

+4
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,10 @@ type ClientTerminateWorkflowInput = internal.ClientTerminateWorkflowInput
196196
// ClientOutboundInterceptor.QueryWorkflow.
197197
type ClientQueryWorkflowInput = internal.ClientQueryWorkflowInput
198198

199+
// ScheduleClientCreateInput is input for
200+
// ScheduleClientInterceptor.CreateSchedule.
201+
type ScheduleClientCreateInput = internal.ScheduleClientCreateInput
202+
199203
// Header provides Temporal header information from the context for reading or
200204
// writing during specific interceptor calls.
201205
//

interceptor/tracing_interceptor.go

+19
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,25 @@ type tracingClientOutboundInterceptor struct {
221221
root *tracingInterceptor
222222
}
223223

224+
func (t *tracingClientOutboundInterceptor) CreateSchedule(ctx context.Context, in *ScheduleClientCreateInput) (client.ScheduleHandle, error) {
225+
// Start span and write to header
226+
span, ctx, err := t.root.startSpanFromContext(ctx, &TracerStartSpanOptions{
227+
Operation: "CreateSchedule",
228+
Name: in.Options.ID,
229+
ToHeader: true,
230+
Time: time.Now(),
231+
})
232+
if err != nil {
233+
return nil, err
234+
}
235+
var finishOpts TracerFinishSpanOptions
236+
defer span.Finish(&finishOpts)
237+
238+
run, err := t.Next.CreateSchedule(ctx, in)
239+
finishOpts.Error = err
240+
return run, err
241+
}
242+
224243
func (t *tracingClientOutboundInterceptor) ExecuteWorkflow(
225244
ctx context.Context,
226245
in *ClientExecuteWorkflowInput,

internal/client.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,9 @@ type (
348348
// OperatorService creates a new operator service client with the same gRPC connection as this client.
349349
OperatorService() operatorservice.OperatorServiceClient
350350

351+
// Schedule creates a new shedule client with the same gRPC connection as this client.
352+
ScheduleClient() ScheduleClient
353+
351354
// Close client and clean up underlying resources.
352355
Close()
353356
}
@@ -395,7 +398,7 @@ type (
395398
DataConverter converter.DataConverter
396399

397400
// Optional: Sets FailureConverter to customize serialization/deserialization of errors.
398-
// default: temporal.DefaultFailureConverter, does not encode any fields of the error. Use temporal.NewDefaultFailureConverter
401+
// default: temporal.DefaultFailureConverter, does not encode any fields of the error. Use temporal.NewDefaultFailureConverter
399402
// options to configure or create a custom converter.
400403
FailureConverter converter.FailureConverter
401404

internal/error.go

+6
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,12 @@ var (
271271
// which indicate the activity is not done yet. Then, when the waited human action happened, it needs to trigger something
272272
// that could report the activity completed event to temporal server via Client.CompleteActivity() API.
273273
ErrActivityResultPending = errors.New("not error: do not autocomplete, using Client.CompleteActivity() to complete")
274+
275+
// ErrScheduleAlreadyRunning is returned if there's already a running (not deleted) Schedule with the same ID
276+
ErrScheduleAlreadyRunning = errors.New("schedule with this ID is already registered")
277+
278+
// ErrSkipScheduleUpdate is used by a user if they want to skip updating a schedule.
279+
ErrSkipScheduleUpdate = errors.New("skip schedule update")
274280
)
275281

276282
// NewApplicationError create new instance of *ApplicationError with message, type, and optional details.

internal/interceptor.go

+9
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,9 @@ type ClientOutboundInterceptor interface {
278278
// interceptor.Header will return a non-nil map for this context.
279279
ExecuteWorkflow(context.Context, *ClientExecuteWorkflowInput) (WorkflowRun, error)
280280

281+
// CreateSchedule - Intercept a service call to CreateSchedule
282+
CreateSchedule(ctx context.Context, options *ScheduleClientCreateInput) (ScheduleHandle, error)
283+
281284
// SignalWorkflow intercepts client.Client.SignalWorkflow.
282285
// interceptor.Header will return a non-nil map for this context.
283286
SignalWorkflow(context.Context, *ClientSignalWorkflowInput) error
@@ -299,6 +302,12 @@ type ClientOutboundInterceptor interface {
299302
mustEmbedClientOutboundInterceptorBase()
300303
}
301304

305+
// ScheduleClientCreateInput is the input to
306+
// ClientOutboundInterceptor.CreateSchedule.
307+
type ScheduleClientCreateInput struct {
308+
Options *ScheduleOptions
309+
}
310+
302311
// ClientExecuteWorkflowInput is the input to
303312
// ClientOutboundInterceptor.ExecuteWorkflow.
304313
type ClientExecuteWorkflowInput struct {

internal/interceptor_base.go

+5
Original file line numberDiff line numberDiff line change
@@ -429,4 +429,9 @@ func (c *ClientOutboundInterceptorBase) QueryWorkflow(
429429
return c.Next.QueryWorkflow(ctx, in)
430430
}
431431

432+
// ExecuteWorkflow implements ClientOutboundInterceptor.CreateSchedule.
433+
func (c *ClientOutboundInterceptorBase) CreateSchedule(ctx context.Context, in *ScheduleClientCreateInput) (ScheduleHandle, error) {
434+
return c.Next.CreateSchedule(ctx, in)
435+
}
436+
432437
func (*ClientOutboundInterceptorBase) mustEmbedClientOutboundInterceptorBase() {}

0 commit comments

Comments
 (0)