1
- import { Construct } from " constructs" ;
2
- import { renderJsonPath , State } from " ./state" ;
3
- import * as cloudwatch from " ../../../aws-cloudwatch" ;
4
- import * as iam from " ../../../aws-iam" ;
5
- import * as cdk from " ../../../core" ;
6
- import { Chain } from " ../chain" ;
7
- import { FieldUtils } from " ../fields" ;
8
- import { StateGraph } from " ../state-graph" ;
9
- import { Credentials } from " ../task-credentials" ;
10
- import { CatchProps , IChainable , INextable , RetryProps } from " ../types" ;
1
+ import { Construct } from ' constructs' ;
2
+ import { renderJsonPath , State } from ' ./state' ;
3
+ import * as cloudwatch from ' ../../../aws-cloudwatch' ;
4
+ import * as iam from ' ../../../aws-iam' ;
5
+ import * as cdk from ' ../../../core' ;
6
+ import { Chain } from ' ../chain' ;
7
+ import { FieldUtils } from ' ../fields' ;
8
+ import { StateGraph } from ' ../state-graph' ;
9
+ import { Credentials } from ' ../task-credentials' ;
10
+ import { CatchProps , IChainable , INextable , RetryProps } from ' ../types' ;
11
11
12
12
/**
13
13
* Props that are common to all tasks
@@ -146,6 +146,7 @@ export interface TaskStateBaseProps {
146
146
* which are more convenient to use.
147
147
*/
148
148
export abstract class TaskStateBase extends State implements INextable {
149
+
149
150
public readonly endStates : INextable [ ] ;
150
151
151
152
protected abstract readonly taskMetrics ?: TaskMetricsConfig ;
@@ -215,15 +216,12 @@ export abstract class TaskStateBase extends State implements INextable {
215
216
*
216
217
* @default - sum over 5 minutes
217
218
*/
218
- public metric (
219
- metricName : string ,
220
- props ?: cloudwatch . MetricOptions
221
- ) : cloudwatch . Metric {
219
+ public metric ( metricName : string , props ?: cloudwatch . MetricOptions ) : cloudwatch . Metric {
222
220
return new cloudwatch . Metric ( {
223
- namespace : " AWS/States" ,
221
+ namespace : ' AWS/States' ,
224
222
metricName,
225
223
dimensionsMap : this . taskMetrics ?. metricDimensions ,
226
- statistic : " sum" ,
224
+ statistic : ' sum' ,
227
225
...props ,
228
226
} ) . attachTo ( this ) ;
229
227
}
@@ -234,25 +232,16 @@ export abstract class TaskStateBase extends State implements INextable {
234
232
* @default - average over 5 minutes
235
233
*/
236
234
public metricRunTime ( props ?: cloudwatch . MetricOptions ) : cloudwatch . Metric {
237
- return this . taskMetric ( this . taskMetrics ?. metricPrefixSingular , "RunTime" , {
238
- statistic : "avg" ,
239
- ...props ,
240
- } ) ;
235
+ return this . taskMetric ( this . taskMetrics ?. metricPrefixSingular , 'RunTime' , { statistic : 'avg' , ...props } ) ;
241
236
}
242
237
243
238
/**
244
239
* The interval, in milliseconds, for which the activity stays in the schedule state.
245
240
*
246
241
* @default - average over 5 minutes
247
242
*/
248
- public metricScheduleTime (
249
- props ?: cloudwatch . MetricOptions
250
- ) : cloudwatch . Metric {
251
- return this . taskMetric (
252
- this . taskMetrics ?. metricPrefixSingular ,
253
- "ScheduleTime" ,
254
- { statistic : "avg" , ...props }
255
- ) ;
243
+ public metricScheduleTime ( props ?: cloudwatch . MetricOptions ) : cloudwatch . Metric {
244
+ return this . taskMetric ( this . taskMetrics ?. metricPrefixSingular , 'ScheduleTime' , { statistic : 'avg' , ...props } ) ;
256
245
}
257
246
258
247
/**
@@ -261,10 +250,7 @@ export abstract class TaskStateBase extends State implements INextable {
261
250
* @default - average over 5 minutes
262
251
*/
263
252
public metricTime ( props ?: cloudwatch . MetricOptions ) : cloudwatch . Metric {
264
- return this . taskMetric ( this . taskMetrics ?. metricPrefixSingular , "Time" , {
265
- statistic : "avg" ,
266
- ...props ,
267
- } ) ;
253
+ return this . taskMetric ( this . taskMetrics ?. metricPrefixSingular , 'Time' , { statistic : 'avg' , ...props } ) ;
268
254
}
269
255
270
256
/**
@@ -273,11 +259,7 @@ export abstract class TaskStateBase extends State implements INextable {
273
259
* @default - sum over 5 minutes
274
260
*/
275
261
public metricScheduled ( props ?: cloudwatch . MetricOptions ) : cloudwatch . Metric {
276
- return this . taskMetric (
277
- this . taskMetrics ?. metricPrefixPlural ,
278
- "Scheduled" ,
279
- props
280
- ) ;
262
+ return this . taskMetric ( this . taskMetrics ?. metricPrefixPlural , 'Scheduled' , props ) ;
281
263
}
282
264
283
265
/**
@@ -286,11 +268,7 @@ export abstract class TaskStateBase extends State implements INextable {
286
268
* @default - sum over 5 minutes
287
269
*/
288
270
public metricTimedOut ( props ?: cloudwatch . MetricOptions ) : cloudwatch . Metric {
289
- return this . taskMetric (
290
- this . taskMetrics ?. metricPrefixPlural ,
291
- "TimedOut" ,
292
- props
293
- ) ;
271
+ return this . taskMetric ( this . taskMetrics ?. metricPrefixPlural , 'TimedOut' , props ) ;
294
272
}
295
273
296
274
/**
@@ -299,11 +277,7 @@ export abstract class TaskStateBase extends State implements INextable {
299
277
* @default - sum over 5 minutes
300
278
*/
301
279
public metricStarted ( props ?: cloudwatch . MetricOptions ) : cloudwatch . Metric {
302
- return this . taskMetric (
303
- this . taskMetrics ?. metricPrefixPlural ,
304
- "Started" ,
305
- props
306
- ) ;
280
+ return this . taskMetric ( this . taskMetrics ?. metricPrefixPlural , 'Started' , props ) ;
307
281
}
308
282
309
283
/**
@@ -312,11 +286,7 @@ export abstract class TaskStateBase extends State implements INextable {
312
286
* @default - sum over 5 minutes
313
287
*/
314
288
public metricSucceeded ( props ?: cloudwatch . MetricOptions ) : cloudwatch . Metric {
315
- return this . taskMetric (
316
- this . taskMetrics ?. metricPrefixPlural ,
317
- "Succeeded" ,
318
- props
319
- ) ;
289
+ return this . taskMetric ( this . taskMetrics ?. metricPrefixPlural , 'Succeeded' , props ) ;
320
290
}
321
291
322
292
/**
@@ -325,26 +295,16 @@ export abstract class TaskStateBase extends State implements INextable {
325
295
* @default - sum over 5 minutes
326
296
*/
327
297
public metricFailed ( props ?: cloudwatch . MetricOptions ) : cloudwatch . Metric {
328
- return this . taskMetric (
329
- this . taskMetrics ?. metricPrefixPlural ,
330
- "Failed" ,
331
- props
332
- ) ;
298
+ return this . taskMetric ( this . taskMetrics ?. metricPrefixPlural , 'Failed' , props ) ;
333
299
}
334
300
335
301
/**
336
302
* Metric for the number of times the heartbeat times out for this activity
337
303
*
338
304
* @default - sum over 5 minutes
339
305
*/
340
- public metricHeartbeatTimedOut (
341
- props ?: cloudwatch . MetricOptions
342
- ) : cloudwatch . Metric {
343
- return this . taskMetric (
344
- this . taskMetrics ?. metricPrefixPlural ,
345
- "HeartbeatTimedOut" ,
346
- props
347
- ) ;
306
+ public metricHeartbeatTimedOut ( props ?: cloudwatch . MetricOptions ) : cloudwatch . Metric {
307
+ return this . taskMetric ( this . taskMetrics ?. metricPrefixPlural , 'HeartbeatTimedOut' , props ) ;
348
308
}
349
309
350
310
protected whenBoundToGraph ( graph : StateGraph ) {
@@ -353,13 +313,11 @@ export abstract class TaskStateBase extends State implements INextable {
353
313
graph . registerPolicyStatement ( policyStatement ) ;
354
314
}
355
315
if ( this . credentials ) {
356
- graph . registerPolicyStatement (
357
- new iam . PolicyStatement ( {
358
- effect : iam . Effect . ALLOW ,
359
- actions : [ "sts:AssumeRole" ] ,
360
- resources : [ this . credentials . role . resource ] ,
361
- } )
362
- ) ;
316
+ graph . registerPolicyStatement ( new iam . PolicyStatement ( {
317
+ effect : iam . Effect . ALLOW ,
318
+ actions : [ 'sts:AssumeRole' ] ,
319
+ resources : [ this . credentials . role . resource ] ,
320
+ } ) ) ;
363
321
}
364
322
}
365
323
@@ -368,35 +326,24 @@ export abstract class TaskStateBase extends State implements INextable {
368
326
*/
369
327
protected abstract _renderTask ( ) : any ;
370
328
371
- private taskMetric (
372
- prefix : string | undefined ,
373
- suffix : string ,
374
- props ?: cloudwatch . MetricOptions
375
- ) : cloudwatch . Metric {
329
+ private taskMetric ( prefix : string | undefined , suffix : string , props ?: cloudwatch . MetricOptions ) : cloudwatch . Metric {
376
330
if ( prefix === undefined ) {
377
- throw new Error (
378
- "Task does not expose metrics. Use the 'metric()' function to add metrics."
379
- ) ;
331
+ throw new Error ( 'Task does not expose metrics. Use the \'metric()\' function to add metrics.' ) ;
380
332
}
381
333
return this . metric ( prefix + suffix , props ) ;
382
334
}
383
335
384
336
private renderCredentials ( ) {
385
- return this . credentials
386
- ? FieldUtils . renderObject ( {
387
- Credentials : { RoleArn : this . credentials . role . roleArn } ,
388
- } )
389
- : undefined ;
337
+ return this . credentials ? FieldUtils . renderObject ( { Credentials : { RoleArn : this . credentials . role . roleArn } } ) : undefined ;
390
338
}
391
339
392
340
private renderTaskBase ( ) {
393
341
return {
394
- Type : " Task" ,
342
+ Type : ' Task' ,
395
343
Comment : this . comment ,
396
344
TimeoutSeconds : this . timeout ?. toSeconds ( ) ?? this . taskTimeout ?. seconds ,
397
345
TimeoutSecondsPath : this . taskTimeout ?. path ,
398
- HeartbeatSeconds :
399
- this . heartbeat ?. toSeconds ( ) ?? this . heartbeatTimeout ?. seconds ,
346
+ HeartbeatSeconds : this . heartbeat ?. toSeconds ( ) ?? this . heartbeatTimeout ?. seconds ,
400
347
HeartbeatSecondsPath : this . heartbeatTimeout ?. path ,
401
348
InputPath : renderJsonPath ( this . inputPath ) ,
402
349
OutputPath : renderJsonPath ( this . outputPath ) ,
@@ -447,22 +394,22 @@ export enum IntegrationPattern {
447
394
*
448
395
* @see https://docs.aws.amazon.com/step-functions/latest/dg/connect-to-resource.html#connect-default
449
396
*/
450
- REQUEST_RESPONSE = " REQUEST_RESPONSE" ,
397
+ REQUEST_RESPONSE = ' REQUEST_RESPONSE' ,
451
398
452
399
/**
453
400
* Step Functions can wait for a request to complete before progressing to the next state.
454
401
*
455
402
* @see https://docs.aws.amazon.com/step-functions/latest/dg/connect-to-resource.html#connect-sync
456
403
*/
457
- RUN_JOB = " RUN_JOB" ,
404
+ RUN_JOB = ' RUN_JOB' ,
458
405
459
406
/**
460
407
* Callback tasks provide a way to pause a workflow until a task token is returned.
461
408
* You must set a task token when using the callback pattern
462
409
*
463
410
* @see https://docs.aws.amazon.com/step-functions/latest/dg/connect-to-resource.html#connect-wait-token
464
411
*/
465
- WAIT_FOR_TASK_TOKEN = " WAIT_FOR_TASK_TOKEN" ,
412
+ WAIT_FOR_TASK_TOKEN = ' WAIT_FOR_TASK_TOKEN' ,
466
413
}
467
414
468
415
/**
0 commit comments