-
Notifications
You must be signed in to change notification settings - Fork 800
/
workflow.go
458 lines (455 loc) · 13 KB
/
workflow.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
// Copyright (c) 2017 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
package cli
import "github.com/urfave/cli"
func newWorkflowCommands() []cli.Command {
return []cli.Command{
{
Name: "show",
Usage: "show workflow history",
Flags: []cli.Flag{
cli.StringFlag{
Name: FlagWorkflowIDWithAlias,
Usage: "WorkflowID",
},
cli.StringFlag{
Name: FlagRunIDWithAlias,
Usage: "RunID",
},
cli.BoolFlag{
Name: FlagPrintDateTimeWithAlias,
Usage: "Print time stamp",
},
cli.BoolFlag{
Name: FlagPrintRawTimeWithAlias,
Usage: "Print raw time stamp",
},
cli.StringFlag{
Name: FlagOutputFilenameWithAlias,
Usage: "Serialize history event to a file",
},
},
Action: func(c *cli.Context) {
ShowHistory(c)
},
},
{
Name: "showid",
Usage: "show workflow history with given workflow_id and optional run_id (a shortcut of `show -w <wid> -r <rid>`)",
Description: "cadence workflow showid <workflow_id> <run_id>. workflow_id is required; run_id is optional",
Flags: []cli.Flag{
cli.BoolFlag{
Name: FlagPrintDateTimeWithAlias,
Usage: "Print time stamp",
},
cli.BoolFlag{
Name: FlagPrintRawTimeWithAlias,
Usage: "Print raw time stamp",
},
cli.StringFlag{
Name: FlagOutputFilenameWithAlias,
Usage: "Serialize history event to a file",
},
},
Action: func(c *cli.Context) {
ShowHistoryWithWID(c)
},
},
{
Name: "start",
Usage: "start a new workflow execution",
Flags: []cli.Flag{
cli.StringFlag{
Name: FlagTaskListWithAlias,
Usage: "TaskList",
},
cli.StringFlag{
Name: FlagWorkflowIDWithAlias,
Usage: "WorkflowID",
},
cli.StringFlag{
Name: FlagWorkflowTypeWithAlias,
Usage: "WorkflowTypeName",
},
cli.IntFlag{
Name: FlagExecutionTimeoutWithAlias,
Usage: "Execution start to close timeout in seconds",
},
cli.IntFlag{
Name: FlagDecisionTimeoutWithAlias,
Value: defaultDecisionTimeoutInSeconds,
Usage: "Decision task start to close timeout in seconds",
},
cli.StringFlag{
Name: FlagInputWithAlias,
Usage: "Optional input for the workflow, in JSON format. If there are multiple parameters, concatenate them and separate by space.",
},
cli.StringFlag{
Name: FlagInputFileWithAlias,
Usage: "Optional input for the workflow from JSON file. If there are multiple JSON, concatenate them and separate by space or newline. " +
"Input from file will be overwrite by input from command line",
},
},
Action: func(c *cli.Context) {
StartWorkflow(c)
},
},
{
Name: "run",
Usage: "start a new workflow execution and get workflow progress",
Flags: []cli.Flag{
cli.StringFlag{
Name: FlagTaskListWithAlias,
Usage: "TaskList",
},
cli.StringFlag{
Name: FlagWorkflowIDWithAlias,
Usage: "WorkflowID",
},
cli.StringFlag{
Name: FlagWorkflowTypeWithAlias,
Usage: "WorkflowTypeName",
},
cli.IntFlag{
Name: FlagExecutionTimeoutWithAlias,
Usage: "Execution start to close timeout in seconds",
},
cli.IntFlag{
Name: FlagDecisionTimeoutWithAlias,
Value: defaultDecisionTimeoutInSeconds,
Usage: "Decision task start to close timeout in seconds",
},
cli.IntFlag{
Name: FlagContextTimeoutWithAlias,
Usage: "Optional timeout for start command context in seconds, default value is 120",
},
cli.StringFlag{
Name: FlagInputWithAlias,
Usage: "Optional input for the workflow, in JSON format. If there are multiple parameters, concatenate them and separate by space.",
},
cli.StringFlag{
Name: FlagInputFileWithAlias,
Usage: "Optional input for the workflow from JSON file. If there are multiple JSON, concatenate them and separate by space or newline. " +
"Input from file will be overwrite by input from command line",
},
cli.BoolFlag{
Name: FlagShowDetailWithAlias,
Usage: "Show event details",
},
},
Action: func(c *cli.Context) {
RunWorkflow(c)
},
},
{
Name: "cancel",
Aliases: []string{"c"},
Usage: "cancel a workflow execution",
Flags: []cli.Flag{
cli.StringFlag{
Name: FlagWorkflowIDWithAlias,
Usage: "WorkflowID",
},
cli.StringFlag{
Name: FlagRunIDWithAlias,
Usage: "RunID",
},
},
Action: func(c *cli.Context) {
CancelWorkflow(c)
},
},
{
Name: "signal",
Aliases: []string{"s"},
Usage: "signal a workflow execution",
Flags: []cli.Flag{
cli.StringFlag{
Name: FlagWorkflowIDWithAlias,
Usage: "WorkflowID",
},
cli.StringFlag{
Name: FlagRunIDWithAlias,
Usage: "RunID",
},
cli.StringFlag{
Name: FlagNameWithAlias,
Usage: "SignalName",
},
cli.StringFlag{
Name: FlagInputWithAlias,
Usage: "Input for the signal, in JSON format.",
},
cli.StringFlag{
Name: FlagInputFileWithAlias,
Usage: "Input for the signal from JSON file.",
},
},
Action: func(c *cli.Context) {
SignalWorkflow(c)
},
},
{
Name: "terminate",
Aliases: []string{"term"},
Usage: "terminate a new workflow execution",
Flags: []cli.Flag{
cli.StringFlag{
Name: FlagWorkflowIDWithAlias,
Usage: "WorkflowID",
},
cli.StringFlag{
Name: FlagRunIDWithAlias,
Usage: "RunID",
},
cli.StringFlag{
Name: FlagReasonWithAlias,
Usage: "The reason you want to terminate the workflow",
},
},
Action: func(c *cli.Context) {
TerminateWorkflow(c)
},
},
{
Name: "list",
Aliases: []string{"l"},
Usage: "list open or closed workflow executions",
Description: "list one page (default size 10 items) by default, use flag --pagesize to change page size",
Flags: []cli.Flag{
cli.BoolFlag{
Name: FlagOpenWithAlias,
Usage: "List for open workflow executions, default is to list for closed ones",
},
cli.BoolFlag{
Name: FlagMoreWithAlias,
Usage: "List more pages, default is to list one page of default page size 10",
},
cli.IntFlag{
Name: FlagPageSizeWithAlias,
Value: 10,
Usage: "Result page size",
},
cli.StringFlag{
Name: FlagEarliestTimeWithAlias,
Usage: "EarliestTime of start time, supported formats are '2006-01-02T15:04:05Z07:00' and raw UnixNano",
},
cli.StringFlag{
Name: FlagLatestTimeWithAlias,
Usage: "LatestTime of start time, supported formats are '2006-01-02T15:04:05Z07:00' and raw UnixNano",
},
cli.StringFlag{
Name: FlagWorkflowIDWithAlias,
Usage: "WorkflowID",
},
cli.StringFlag{
Name: FlagWorkflowTypeWithAlias,
Usage: "WorkflowTypeName",
},
cli.BoolFlag{
Name: FlagPrintRawTimeWithAlias,
Usage: "Print raw time stamp",
},
cli.BoolFlag{
Name: FlagPrintDateTimeWithAlias,
Usage: "Print full date time in '2006-01-02T15:04:05Z07:00' format",
},
},
Action: func(c *cli.Context) {
ListWorkflow(c)
},
},
{
Name: "listall",
Aliases: []string{"la"},
Usage: "list all open or closed workflow executions",
Flags: []cli.Flag{
cli.BoolFlag{
Name: FlagOpenWithAlias,
Usage: "List for open workflow executions, default is to list for closed ones",
},
cli.StringFlag{
Name: FlagEarliestTimeWithAlias,
Usage: "EarliestTime of start time, supported formats are '2006-01-02T15:04:05Z07:00' and raw UnixNano",
},
cli.StringFlag{
Name: FlagLatestTimeWithAlias,
Usage: "LatestTime of start time, supported formats are '2006-01-02T15:04:05Z07:00' and raw UnixNano",
},
cli.StringFlag{
Name: FlagWorkflowIDWithAlias,
Usage: "WorkflowID",
},
cli.StringFlag{
Name: FlagWorkflowTypeWithAlias,
Usage: "WorkflowTypeName",
},
cli.BoolFlag{
Name: FlagPrintRawTimeWithAlias,
Usage: "Print raw time stamp",
},
cli.BoolFlag{
Name: FlagPrintDateTimeWithAlias,
Usage: "Print full date time in '2006-01-02T15:04:05Z07:00' format",
},
},
Action: func(c *cli.Context) {
ListAllWorkflow(c)
},
},
{
Name: "query",
Usage: "query workflow execution",
Flags: []cli.Flag{
cli.StringFlag{
Name: FlagWorkflowIDWithAlias,
Usage: "WorkflowID",
},
cli.StringFlag{
Name: FlagRunIDWithAlias,
Usage: "RunID",
},
cli.StringFlag{
Name: FlagQueryTypeWithAlias,
Usage: "The query type you want to run",
},
cli.StringFlag{
Name: FlagInputWithAlias,
Usage: "Optional input for the query, in JSON format. If there are multiple parameters, concatenate them and separate by space.",
},
cli.StringFlag{
Name: FlagInputFileWithAlias,
Usage: "Optional input for the query from JSON file. If there are multiple JSON, concatenate them and separate by space or newline. " +
"Input from file will be overwrite by input from command line",
},
},
Action: func(c *cli.Context) {
QueryWorkflow(c)
},
},
{
Name: "stack",
Usage: "query workflow execution with __stack_trace as query type",
Flags: []cli.Flag{
cli.StringFlag{
Name: FlagWorkflowIDWithAlias,
Usage: "WorkflowID",
},
cli.StringFlag{
Name: FlagRunIDWithAlias,
Usage: "RunID",
},
cli.StringFlag{
Name: FlagInputWithAlias,
Usage: "Optional input for the query, in JSON format. If there are multiple parameters, concatenate them and separate by space.",
},
cli.StringFlag{
Name: FlagInputFileWithAlias,
Usage: "Optional input for the query from JSON file. If there are multiple JSON, concatenate them and separate by space or newline. " +
"Input from file will be overwrite by input from command line",
},
},
Action: func(c *cli.Context) {
QueryWorkflowUsingStackTrace(c)
},
},
{
Name: "describe",
Aliases: []string{"desc"},
Usage: "show information of workflow execution",
Flags: []cli.Flag{
cli.StringFlag{
Name: FlagWorkflowIDWithAlias,
Usage: "WorkflowID",
},
cli.StringFlag{
Name: FlagRunIDWithAlias,
Usage: "RunID",
},
cli.BoolFlag{
Name: FlagPrintRawTimeWithAlias,
Usage: "Print raw time stamp",
},
},
Action: func(c *cli.Context) {
DescribeWorkflow(c)
},
},
{
Name: "describeid",
Aliases: []string{"descid"},
Usage: "show information of workflow execution with given workflow_id and optional run_id (a shortcut of `describe -w <wid> -r <rid>`)",
Description: "cadence workflow describeid <workflow_id> <run_id>. workflow_id is required; run_id is optional",
Flags: []cli.Flag{
cli.BoolFlag{
Name: FlagPrintRawTimeWithAlias,
Usage: "Print raw time stamp",
},
},
Action: func(c *cli.Context) {
DescribeWorkflowWithID(c)
},
},
{
Name: "observe",
Aliases: []string{"ob"},
Usage: "show the progress of workflow history",
Flags: []cli.Flag{
cli.StringFlag{
Name: FlagWorkflowIDWithAlias,
Usage: "WorkflowID",
},
cli.StringFlag{
Name: FlagRunIDWithAlias,
Usage: "RunID",
},
cli.IntFlag{
Name: FlagContextTimeoutWithAlias,
Usage: "Optional timeout for start command context in seconds, default value is 120",
},
cli.BoolFlag{
Name: FlagShowDetailWithAlias,
Usage: "Show event details",
},
},
Action: func(c *cli.Context) {
ObserveHistory(c)
},
},
{
Name: "observeid",
Aliases: []string{"obid"},
Usage: "show the progress of workflow history with given workflow_id and optional run_id (a shortcut of `observe -w <wid> -r <rid>`)",
Flags: []cli.Flag{
cli.IntFlag{
Name: FlagContextTimeoutWithAlias,
Usage: "Optional timeout for start command context in seconds, default value is 120",
},
cli.BoolFlag{
Name: FlagShowDetailWithAlias,
Usage: "Show event details",
},
},
Action: func(c *cli.Context) {
ObserveHistoryWithID(c)
},
},
}
}