-
Notifications
You must be signed in to change notification settings - Fork 0
/
workflow-history-generator.ts
147 lines (131 loc) · 5.7 KB
/
workflow-history-generator.ts
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
import { HistoryGenerator } from './history-event-generator';
import { HistoryEvent, TaskList } from '../../aws/aws.types';
import { EventType } from '../../aws/workflow-history/event-types';
import {
CancelWorkflowExecutionFailedEventAttributes, ChildPolicy, CompleteWorkflowExecutionFailedEventAttributes,
ContinueAsNewWorkflowExecutionFailedEventAttributes, FailWorkflowExecutionFailedEventAttributes,
WorkflowExecutionCanceledEventAttributes, WorkflowExecutionCancelRequestedEventAttributes,
WorkflowExecutionCompletedEventAttributes, WorkflowExecutionContinuedAsNewEventAttributes, WorkflowExecutionFailedEventAttributes,
WorkflowExecutionStartedEventAttributes, WorkflowExecutionTerminatedEventAttributes, WorkflowExecutionTimedOutEventAttributes, WorkflowType,
} from 'aws-sdk/clients/swf';
export class WorkflowHistoryGenerator extends HistoryGenerator {
constructor(public workflowType: WorkflowType = { name: 'default-test', version: '1' },
public taskList: TaskList = { name: 'default' },
public childPolicy: ChildPolicy = 'TERMINATE') {
super();
}
createStartedEvent(params: Partial<WorkflowExecutionStartedEventAttributes> = {}): HistoryEvent {
const event = this.createHistoryEvent(EventType.WorkflowExecutionStarted);
event.workflowExecutionStartedEventAttributes = {
workflowType: this.workflowType,
taskList: this.taskList,
childPolicy: this.childPolicy,
...params,
};
return event;
}
createCompletedEvent(params: Partial<WorkflowExecutionCompletedEventAttributes> = {}): HistoryEvent {
const event = this.createHistoryEvent(EventType.WorkflowExecutionCompleted);
event.workflowExecutionCompletedEventAttributes = {
decisionTaskCompletedEventId: this.currentEventId - 2,
...params,
};
return event;
}
createCancelRequestedEvent(params: Partial<WorkflowExecutionCancelRequestedEventAttributes>): HistoryEvent {
const event = this.createHistoryEvent(EventType.WorkflowExecutionCancelRequested);
event.workflowExecutionCancelRequestedEventAttributes = {
cause: 'test cause',
externalInitiatedEventId: this.currentEventId - 1,
...params,
};
return event;
}
createCanceledEvent(params: Partial<WorkflowExecutionCanceledEventAttributes>): HistoryEvent {
const event = this.createHistoryEvent(EventType.WorkflowExecutionCanceled);
event.workflowExecutionCanceledEventAttributes = {
decisionTaskCompletedEventId: this.currentEventId - 1,
details: 'test details',
...params,
};
return event;
}
createCancelFailedEvent(params: Partial<CancelWorkflowExecutionFailedEventAttributes>): HistoryEvent {
const event = this.createHistoryEvent(EventType.CancelWorkflowExecutionFailed);
event.cancelWorkflowExecutionFailedEventAttributes = {
cause: 'test cause',
decisionTaskCompletedEventId: this.currentEventId - 1,
...params,
};
return event;
}
createCompleteFailedEvent(params: Partial<CompleteWorkflowExecutionFailedEventAttributes>): HistoryEvent {
const event = this.createHistoryEvent(EventType.CompleteWorkflowExecutionFailed);
event.completeWorkflowExecutionFailedEventAttributes = {
cause: 'test cause',
decisionTaskCompletedEventId: this.currentEventId - 1,
...params,
};
return event;
}
createFailedEvent(params: Partial<WorkflowExecutionFailedEventAttributes>): HistoryEvent {
const event = this.createHistoryEvent(EventType.WorkflowExecutionFailed);
event.workflowExecutionFailedEventAttributes = {
details: 'test details',
reason: 'test reason',
decisionTaskCompletedEventId: this.currentEventId - 1,
...params,
};
return event;
}
createFailFailedEvent(params: Partial<FailWorkflowExecutionFailedEventAttributes>): HistoryEvent {
const event = this.createHistoryEvent(EventType.FailWorkflowExecutionFailed);
event.failWorkflowExecutionFailedEventAttributes = {
cause: 'test cause',
decisionTaskCompletedEventId: this.currentEventId - 1,
...params,
};
return event;
}
createTimedOutEvent(params: Partial<WorkflowExecutionTimedOutEventAttributes>): HistoryEvent {
const event = this.createHistoryEvent(EventType.WorkflowExecutionTimedOut);
event.workflowExecutionTimedOutEventAttributes = {
timeoutType: 'START_TO_CLOSE',
childPolicy: 'TERMINATE',
...params,
};
return event;
}
createContinuedAsNewEvent(params: Partial<WorkflowExecutionContinuedAsNewEventAttributes>): HistoryEvent {
const event = this.createHistoryEvent(EventType.WorkflowExecutionContinuedAsNew);
event.workflowExecutionContinuedAsNewEventAttributes = {
workflowType: this.workflowType,
taskList: this.taskList,
childPolicy: this.childPolicy,
newExecutionRunId: 'new execution run id',
decisionTaskCompletedEventId: this.currentEventId - 1,
...params,
};
return event;
}
createContinueAsNewFailedEvent(params: Partial<ContinueAsNewWorkflowExecutionFailedEventAttributes>): HistoryEvent {
const event = this.createHistoryEvent(EventType.ContinueAsNewWorkflowExecutionFailed);
event.continueAsNewWorkflowExecutionFailedEventAttributes = {
cause: 'test cause',
decisionTaskCompletedEventId: this.currentEventId - 1,
...params,
};
return event;
}
createTerminatedEvent(params: Partial<WorkflowExecutionTerminatedEventAttributes>): HistoryEvent {
const event = this.createHistoryEvent(EventType.WorkflowExecutionTerminated);
event.workflowExecutionTerminatedEventAttributes = {
childPolicy: this.childPolicy,
cause: 'test cause',
details: 'test details',
reason: 'test reason',
...params,
};
return event;
}
}