@@ -89,6 +89,10 @@ export abstract class TaskStateBase extends State implements INextable {
89
89
90
90
public readonly endStates : INextable [ ] ;
91
91
92
+ protected taskMetrics : TaskMetricsConfig = { } ;
93
+
94
+ protected taskPolicies : iam . PolicyStatement [ ] | undefined ;
95
+
92
96
constructor ( scope : cdk . Construct , id : string , props : TaskStateBaseProps ) {
93
97
super ( scope , id , props ) ;
94
98
this . endStates = [ this ] ;
@@ -144,7 +148,7 @@ export abstract class TaskStateBase extends State implements INextable {
144
148
return new cloudwatch . Metric ( {
145
149
namespace : 'AWS/States' ,
146
150
metricName,
147
- dimensions : this . taskMetrics ( ) . metricDimensions ,
151
+ dimensions : this . taskMetrics ? .metricDimensions ,
148
152
statistic : 'sum' ,
149
153
...props ,
150
154
} ) . attachTo ( this ) ;
@@ -156,7 +160,7 @@ export abstract class TaskStateBase extends State implements INextable {
156
160
* @default average over 5 minutes
157
161
*/
158
162
public metricRunTime ( props ?: cloudwatch . MetricOptions ) : cloudwatch . Metric {
159
- return this . taskMetric ( this . taskMetrics ( ) . metricPrefixSingular , 'RunTime' , { statistic : 'avg' , ...props } ) ;
163
+ return this . taskMetric ( this . taskMetrics ? .metricPrefixSingular , 'RunTime' , { statistic : 'avg' , ...props } ) ;
160
164
}
161
165
162
166
/**
@@ -165,7 +169,7 @@ export abstract class TaskStateBase extends State implements INextable {
165
169
* @default average over 5 minutes
166
170
*/
167
171
public metricScheduleTime ( props ?: cloudwatch . MetricOptions ) : cloudwatch . Metric {
168
- return this . taskMetric ( this . taskMetrics ( ) . metricPrefixSingular , 'ScheduleTime' , { statistic : 'avg' , ...props } ) ;
172
+ return this . taskMetric ( this . taskMetrics ? .metricPrefixSingular , 'ScheduleTime' , { statistic : 'avg' , ...props } ) ;
169
173
}
170
174
171
175
/**
@@ -174,7 +178,7 @@ export abstract class TaskStateBase extends State implements INextable {
174
178
* @default average over 5 minutes
175
179
*/
176
180
public metricTime ( props ?: cloudwatch . MetricOptions ) : cloudwatch . Metric {
177
- return this . taskMetric ( this . taskMetrics ( ) . metricPrefixSingular , 'Time' , { statistic : 'avg' , ...props } ) ;
181
+ return this . taskMetric ( this . taskMetrics ? .metricPrefixSingular , 'Time' , { statistic : 'avg' , ...props } ) ;
178
182
}
179
183
180
184
/**
@@ -183,7 +187,7 @@ export abstract class TaskStateBase extends State implements INextable {
183
187
* @default sum over 5 minutes
184
188
*/
185
189
public metricScheduled ( props ?: cloudwatch . MetricOptions ) : cloudwatch . Metric {
186
- return this . taskMetric ( this . taskMetrics ( ) . metricPrefixPlural , 'Scheduled' , props ) ;
190
+ return this . taskMetric ( this . taskMetrics ? .metricPrefixPlural , 'Scheduled' , props ) ;
187
191
}
188
192
189
193
/**
@@ -192,7 +196,7 @@ export abstract class TaskStateBase extends State implements INextable {
192
196
* @default sum over 5 minutes
193
197
*/
194
198
public metricTimedOut ( props ?: cloudwatch . MetricOptions ) : cloudwatch . Metric {
195
- return this . taskMetric ( this . taskMetrics ( ) . metricPrefixPlural , 'TimedOut' , props ) ;
199
+ return this . taskMetric ( this . taskMetrics ? .metricPrefixPlural , 'TimedOut' , props ) ;
196
200
}
197
201
198
202
/**
@@ -201,7 +205,7 @@ export abstract class TaskStateBase extends State implements INextable {
201
205
* @default sum over 5 minutes
202
206
*/
203
207
public metricStarted ( props ?: cloudwatch . MetricOptions ) : cloudwatch . Metric {
204
- return this . taskMetric ( this . taskMetrics ( ) . metricPrefixPlural , 'Started' , props ) ;
208
+ return this . taskMetric ( this . taskMetrics ? .metricPrefixPlural , 'Started' , props ) ;
205
209
}
206
210
207
211
/**
@@ -210,7 +214,7 @@ export abstract class TaskStateBase extends State implements INextable {
210
214
* @default sum over 5 minutes
211
215
*/
212
216
public metricSucceeded ( props ?: cloudwatch . MetricOptions ) : cloudwatch . Metric {
213
- return this . taskMetric ( this . taskMetrics ( ) . metricPrefixPlural , 'Succeeded' , props ) ;
217
+ return this . taskMetric ( this . taskMetrics ? .metricPrefixPlural , 'Succeeded' , props ) ;
214
218
}
215
219
216
220
/**
@@ -219,7 +223,7 @@ export abstract class TaskStateBase extends State implements INextable {
219
223
* @default sum over 5 minutes
220
224
*/
221
225
public metricFailed ( props ?: cloudwatch . MetricOptions ) : cloudwatch . Metric {
222
- return this . taskMetric ( this . taskMetrics ( ) . metricPrefixPlural , 'Failed' , props ) ;
226
+ return this . taskMetric ( this . taskMetrics ? .metricPrefixPlural , 'Failed' , props ) ;
223
227
}
224
228
225
229
/**
@@ -228,20 +232,16 @@ export abstract class TaskStateBase extends State implements INextable {
228
232
* @default sum over 5 minutes
229
233
*/
230
234
public metricHeartbeatTimedOut ( props ?: cloudwatch . MetricOptions ) : cloudwatch . Metric {
231
- return this . taskMetric ( this . taskMetrics ( ) . metricPrefixPlural , 'HeartbeatTimedOut' , props ) ;
235
+ return this . taskMetric ( this . taskMetrics ? .metricPrefixPlural , 'HeartbeatTimedOut' , props ) ;
232
236
}
233
237
234
238
protected whenBoundToGraph ( graph : StateGraph ) {
235
239
super . whenBoundToGraph ( graph ) ;
236
- for ( const policyStatement of this . taskPolicies ( ) || [ ] ) {
240
+ for ( const policyStatement of this . taskPolicies || [ ] ) {
237
241
graph . registerPolicyStatement ( policyStatement ) ;
238
242
}
239
243
}
240
244
241
- protected abstract taskMetrics ( ) : TaskMetricsConfig ;
242
-
243
- protected abstract taskPolicies ( ) : iam . PolicyStatement [ ] ;
244
-
245
245
protected abstract renderTask ( ) : any ;
246
246
247
247
private taskMetric ( prefix : string | undefined , suffix : string , props ?: cloudwatch . MetricOptions ) : cloudwatch . Metric {
0 commit comments