/
workflow.go
494 lines (487 loc) · 14.3 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
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
// 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 (
"strings"
"github.com/urfave/cli"
"github.com/uber/cadence/service/worker/batcher"
)
func newWorkflowCommands() []cli.Command {
return []cli.Command{
{
Name: "activity",
Aliases: []string{"act"},
Usage: "operate activities of workflow",
Subcommands: newActivityCommands(),
},
{
Name: "show",
Usage: "show workflow history",
Flags: getFlagsForShow(),
Action: func(c *cli.Context) {
ShowHistory(c)
},
},
{
Name: "showid",
Usage: "show workflow history with given workflow_id and run_id (a shortcut of `show -w <wid> -r <rid>`). run_id is only required for archived history",
Description: "cadence workflow showid <workflow_id> <run_id>. workflow_id is required; run_id is only required for archived history",
Flags: getFlagsForShowID(),
Action: func(c *cli.Context) {
ShowHistoryWithWID(c)
},
},
{
Name: "start",
Usage: "start a new workflow execution",
Flags: getFlagsForStart(),
Action: func(c *cli.Context) {
StartWorkflow(c)
},
},
{
Name: "run",
Usage: "start a new workflow execution and get workflow progress",
Flags: getFlagsForRun(),
Action: func(c *cli.Context) {
RunWorkflow(c)
},
},
{
Name: "cancel",
Aliases: []string{"c"},
Usage: "cancel a workflow execution",
Flags: flagsForExecution,
Action: func(c *cli.Context) {
CancelWorkflow(c)
},
},
{
Name: "signal",
Aliases: []string{"s"},
Usage: "signal a workflow execution",
Flags: getFlagsForSignal(),
Action: func(c *cli.Context) {
SignalWorkflow(c)
},
},
{
Name: "signalwithstart",
Usage: "signal the current open workflow if exists, or attempt to start a new run based on IDResuePolicy and signals it",
Flags: getFlagsForSignalWithStart(),
Action: func(c *cli.Context) {
SignalWithStartWorkflowExecution(c)
},
},
{
Name: "terminate",
Aliases: []string{"term"},
Usage: "terminate a new workflow execution",
Flags: getFlagsForTerminate(),
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: getFlagsForList(),
Action: func(c *cli.Context) {
ListWorkflow(c)
},
},
{
Name: "listall",
Aliases: []string{"la"},
Usage: "list all open or closed workflow executions",
Flags: getFlagsForListAll(),
Action: func(c *cli.Context) {
ListAllWorkflow(c)
},
},
{
Name: "listarchived",
Usage: "list archived workflow executions",
Flags: getFlagsForListArchived(),
Action: func(c *cli.Context) {
ListArchivedWorkflow(c)
},
},
{
Name: "scan",
Aliases: []string{"sc", "scanall"},
Usage: "scan workflow executions (need to enable Cadence server on ElasticSearch). " +
"It will be faster than listall, but result are not sorted.",
Flags: getFlagsForScan(),
Action: func(c *cli.Context) {
ScanAllWorkflow(c)
},
},
{
Name: "count",
Aliases: []string{"cnt"},
Usage: "count number of workflow executions (need to enable Cadence server on ElasticSearch)",
Flags: getFlagsForCount(),
Action: func(c *cli.Context) {
CountWorkflow(c)
},
},
{
Name: "query",
Usage: "query workflow execution",
Description: "query result will be printed as JSON",
Flags: getFlagsForQuery(),
Action: func(c *cli.Context) {
QueryWorkflow(c)
},
},
{
Name: "stack",
Usage: "query workflow execution with __stack_trace as query type",
Flags: getFlagsForStack(),
Action: func(c *cli.Context) {
QueryWorkflowUsingStackTrace(c)
},
},
{
Name: "describe",
Aliases: []string{"desc"},
Usage: "show information of workflow execution",
Flags: getFlagsForDescribe(),
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: getFlagsForDescribeID(),
Action: func(c *cli.Context) {
DescribeWorkflowWithID(c)
},
},
{
Name: "observe",
Aliases: []string{"ob"},
Usage: "show the progress of workflow history",
Flags: getFlagsForObserve(),
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: getFlagsForObserveID(),
Action: func(c *cli.Context) {
ObserveHistoryWithID(c)
},
},
{
Name: "reset",
Aliases: []string{"rs"},
Usage: "reset the workflow, by either eventID or resetType.",
Flags: []cli.Flag{
cli.StringFlag{
Name: FlagWorkflowIDWithAlias,
Usage: "WorkflowID, required",
},
cli.StringFlag{
Name: FlagRunIDWithAlias,
Usage: "RunID, optional, default to the current/latest RunID",
},
cli.StringFlag{
Name: FlagEventID,
Usage: "The eventID of any event after DecisionTaskStarted you want to reset to (this event is exclusive in a new run. The new run " +
"history will fork and continue from the previous eventID of this). It can be DecisionTaskCompleted, DecisionTaskFailed or others",
},
cli.StringFlag{
Name: FlagReason,
Usage: "reason to do the reset, required for tracking purpose",
},
cli.StringFlag{
Name: FlagResetType,
Usage: "where to reset. Support one of these: " + strings.Join(mapKeysToArray(resetTypesMap), ","),
},
cli.StringFlag{
Name: FlagResetBadBinaryChecksum,
Usage: "Binary checksum for resetType of BadBinary",
},
cli.StringFlag{
Name: FlagEarliestTimeWithAlias,
Usage: "EarliestTime of decision start time, required for resetType of DecisionCompletedTime." +
"Supported formats are '2006-01-02T15:04:05+07:00', raw UnixNano and " +
"time range (N<duration>), where 0 < N < 1000000 and duration (full-notation/short-notation) can be second/s, " +
"minute/m, hour/h, day/d, week/w, month/M or year/y. For example, '15minute' or '15m' implies last 15 minutes, " +
"meaning that workflow will be reset to the first decision that completed in last 15 minutes.",
},
cli.BoolFlag{
Name: FlagSkipSignalReapply,
Usage: "whether or not skipping signals reapply after the reset point",
},
},
Action: func(c *cli.Context) {
ResetWorkflow(c)
},
},
{
Name: "reset-batch",
Usage: "reset workflow in batch by resetType: " + strings.Join(mapKeysToArray(resetTypesMap), ",") +
"To get base workflowIDs/runIDs to reset, source is from input file or visibility query.",
Flags: []cli.Flag{
cli.StringFlag{
Name: FlagInputFileWithAlias,
Usage: "Input file to use for resetting, one workflow per line of WorkflowID and RunID. RunID is optional, default to current runID if not specified. ",
},
cli.StringFlag{
Name: FlagListQueryWithAlias,
Usage: "visibility query to get workflows to reset",
},
cli.StringFlag{
Name: FlagExcludeFile,
Value: "",
Usage: "Another input file to use for excluding from resetting, only workflowID is needed.",
},
cli.StringFlag{
Name: FlagInputSeparator,
Value: "\t",
Usage: "Separator for input file(default to tab)",
},
cli.StringFlag{
Name: FlagReason,
Usage: "Reason for reset, required for tracking purpose",
},
cli.IntFlag{
Name: FlagParallism,
Value: 1,
Usage: "Number of goroutines to run in parallel. Each goroutine would process one line for every second.",
},
cli.BoolFlag{
Name: FlagSkipCurrentOpen,
Usage: "Skip the workflow if the current run is open for the same workflowID as base.",
},
cli.BoolFlag{
Name: FlagSkipBaseIsNotCurrent,
// TODO https://github.com/uber/cadence/issues/2930
// The right way to prevent needs server side implementation .
// This client side is only best effort
Usage: "Skip if base run is not current run.",
},
cli.BoolFlag{
Name: FlagNonDeterministicOnly,
Usage: "Only apply onto workflows whose last event is decisionTaskFailed with non deterministic error.",
},
cli.BoolFlag{
Name: FlagDryRun,
Usage: "Not do real action of reset(just logging in STDOUT)",
},
cli.StringFlag{
Name: FlagResetType,
Usage: "where to reset. Support one of these: " + strings.Join(mapKeysToArray(resetTypesMap), ","),
},
cli.StringFlag{
Name: FlagResetBadBinaryChecksum,
Usage: "Binary checksum for resetType of BadBinary",
},
cli.BoolFlag{
Name: FlagSkipSignalReapply,
Usage: "whether or not skipping signals reapply after the reset point",
},
cli.StringFlag{
Name: FlagEarliestTimeWithAlias,
Usage: "EarliestTime of decision start time, required for resetType of DecisionCompletedTime." +
"Supported formats are '2006-01-02T15:04:05+07:00', raw UnixNano and " +
"time range (N<duration>), where 0 < N < 1000000 and duration (full-notation/short-notation) can be second/s, " +
"minute/m, hour/h, day/d, week/w, month/M or year/y. For example, '15minute' or '15m' implies last 15 minutes, " +
"meaning that workflow will be reset to the first decision that completed in last 15 minutes.",
},
},
Action: func(c *cli.Context) {
ResetInBatch(c)
},
},
{
Name: "batch",
Usage: "batch operation on a list of workflows from query.",
Subcommands: newBatchCommands(),
},
}
}
func newActivityCommands() []cli.Command {
return []cli.Command{
{
Name: "complete",
Aliases: []string{"comp"},
Usage: "complete an activity",
Flags: []cli.Flag{
cli.StringFlag{
Name: FlagWorkflowIDWithAlias,
Usage: "WorkflowID",
},
cli.StringFlag{
Name: FlagRunIDWithAlias,
Usage: "RunID",
},
cli.StringFlag{
Name: FlagActivityIDWithAlias,
Usage: "The activityID to operate on",
},
cli.StringFlag{
Name: FlagResult,
Usage: "Result of the activity",
},
cli.StringFlag{
Name: FlagIdentity,
Usage: "Identity of the operator",
},
},
Action: func(c *cli.Context) {
CompleteActivity(c)
},
},
{
Name: "fail",
Usage: "fail an activity",
Flags: []cli.Flag{
cli.StringFlag{
Name: FlagWorkflowIDWithAlias,
Usage: "WorkflowID",
},
cli.StringFlag{
Name: FlagRunIDWithAlias,
Usage: "RunID",
},
cli.StringFlag{
Name: FlagActivityIDWithAlias,
Usage: "The activityID to operate on",
},
cli.StringFlag{
Name: FlagReason,
Usage: "Reason to fail the activity",
},
cli.StringFlag{
Name: FlagDetail,
Usage: "Detail to fail the activity",
},
cli.StringFlag{
Name: FlagIdentity,
Usage: "Identity of the operator",
},
},
Action: func(c *cli.Context) {
FailActivity(c)
},
},
}
}
func newBatchCommands() []cli.Command {
return []cli.Command{
{
Name: "describe",
Aliases: []string{"desc"},
Usage: "Describe a batch operation job",
Flags: []cli.Flag{
cli.StringFlag{
Name: FlagJobIDWithAlias,
Usage: "Batch Job ID",
},
},
Action: func(c *cli.Context) {
DescribeBatchJob(c)
},
},
{
Name: "terminate",
Usage: "terminate a batch operation job",
Flags: []cli.Flag{
cli.StringFlag{
Name: FlagJobIDWithAlias,
Usage: "Batch Job ID",
},
cli.StringFlag{
Name: FlagReasonWithAlias,
Usage: "Reason to stop this batch job",
},
},
Action: func(c *cli.Context) {
TerminateBatchJob(c)
},
},
{
Name: "list",
Aliases: []string{"l"},
Usage: "Describe a batch operation job",
Flags: []cli.Flag{
cli.IntFlag{
Name: FlagPageSizeWithAlias,
Value: 30,
Usage: "Result page size",
},
},
Action: func(c *cli.Context) {
ListBatchJobs(c)
},
},
{
Name: "start",
Usage: "Start a batch operation job",
Flags: []cli.Flag{
cli.StringFlag{
Name: FlagListQueryWithAlias,
Usage: "Query to get workflows for being executed this batch operation",
},
cli.StringFlag{
Name: FlagReasonWithAlias,
Usage: "Reason to run this batch job",
},
cli.StringFlag{
Name: FlagBatchTypeWithAlias,
Usage: "Types supported: " + strings.Join(batcher.AllBatchTypes, ","),
},
//below are optional
cli.StringFlag{
Name: FlagSignalNameWithAlias,
Usage: "Required for batch signal",
},
cli.StringFlag{
Name: FlagInputWithAlias,
Usage: "Optional input of signal",
},
cli.IntFlag{
Name: FlagRPS,
Value: batcher.DefaultRPS,
Usage: "RPS of processing",
},
cli.BoolFlag{
Name: FlagYes,
Usage: "Optional flag to disable confirmation prompt",
},
},
Action: func(c *cli.Context) {
StartBatchJob(c)
},
},
}
}