Skip to content

Commit

Permalink
reverting prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
Rizbir Fahmid Khan committed Feb 7, 2024
1 parent 86999f3 commit 9c5f521
Showing 1 changed file with 38 additions and 91 deletions.
129 changes: 38 additions & 91 deletions packages/aws-cdk-lib/aws-stepfunctions/lib/states/task-base.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Construct } from "constructs";
import { renderJsonPath, State } from "./state";
import * as cloudwatch from "../../../aws-cloudwatch";
import * as iam from "../../../aws-iam";
import * as cdk from "../../../core";
import { Chain } from "../chain";
import { FieldUtils } from "../fields";
import { StateGraph } from "../state-graph";
import { Credentials } from "../task-credentials";
import { CatchProps, IChainable, INextable, RetryProps } from "../types";
import { Construct } from 'constructs';
import { renderJsonPath, State } from './state';
import * as cloudwatch from '../../../aws-cloudwatch';
import * as iam from '../../../aws-iam';
import * as cdk from '../../../core';
import { Chain } from '../chain';
import { FieldUtils } from '../fields';
import { StateGraph } from '../state-graph';
import { Credentials } from '../task-credentials';
import { CatchProps, IChainable, INextable, RetryProps } from '../types';

/**
* Props that are common to all tasks
Expand Down Expand Up @@ -146,6 +146,7 @@ export interface TaskStateBaseProps {
* which are more convenient to use.
*/
export abstract class TaskStateBase extends State implements INextable {

public readonly endStates: INextable[];

protected abstract readonly taskMetrics?: TaskMetricsConfig;
Expand Down Expand Up @@ -215,15 +216,12 @@ export abstract class TaskStateBase extends State implements INextable {
*
* @default - sum over 5 minutes
*/
public metric(
metricName: string,
props?: cloudwatch.MetricOptions
): cloudwatch.Metric {
public metric(metricName: string, props?: cloudwatch.MetricOptions): cloudwatch.Metric {
return new cloudwatch.Metric({
namespace: "AWS/States",
namespace: 'AWS/States',
metricName,
dimensionsMap: this.taskMetrics?.metricDimensions,
statistic: "sum",
statistic: 'sum',
...props,
}).attachTo(this);
}
Expand All @@ -234,25 +232,16 @@ export abstract class TaskStateBase extends State implements INextable {
* @default - average over 5 minutes
*/
public metricRunTime(props?: cloudwatch.MetricOptions): cloudwatch.Metric {
return this.taskMetric(this.taskMetrics?.metricPrefixSingular, "RunTime", {
statistic: "avg",
...props,
});
return this.taskMetric(this.taskMetrics?.metricPrefixSingular, 'RunTime', { statistic: 'avg', ...props });
}

/**
* The interval, in milliseconds, for which the activity stays in the schedule state.
*
* @default - average over 5 minutes
*/
public metricScheduleTime(
props?: cloudwatch.MetricOptions
): cloudwatch.Metric {
return this.taskMetric(
this.taskMetrics?.metricPrefixSingular,
"ScheduleTime",
{ statistic: "avg", ...props }
);
public metricScheduleTime(props?: cloudwatch.MetricOptions): cloudwatch.Metric {
return this.taskMetric(this.taskMetrics?.metricPrefixSingular, 'ScheduleTime', { statistic: 'avg', ...props });
}

/**
Expand All @@ -261,10 +250,7 @@ export abstract class TaskStateBase extends State implements INextable {
* @default - average over 5 minutes
*/
public metricTime(props?: cloudwatch.MetricOptions): cloudwatch.Metric {
return this.taskMetric(this.taskMetrics?.metricPrefixSingular, "Time", {
statistic: "avg",
...props,
});
return this.taskMetric(this.taskMetrics?.metricPrefixSingular, 'Time', { statistic: 'avg', ...props });
}

/**
Expand All @@ -273,11 +259,7 @@ export abstract class TaskStateBase extends State implements INextable {
* @default - sum over 5 minutes
*/
public metricScheduled(props?: cloudwatch.MetricOptions): cloudwatch.Metric {
return this.taskMetric(
this.taskMetrics?.metricPrefixPlural,
"Scheduled",
props
);
return this.taskMetric(this.taskMetrics?.metricPrefixPlural, 'Scheduled', props);
}

/**
Expand All @@ -286,11 +268,7 @@ export abstract class TaskStateBase extends State implements INextable {
* @default - sum over 5 minutes
*/
public metricTimedOut(props?: cloudwatch.MetricOptions): cloudwatch.Metric {
return this.taskMetric(
this.taskMetrics?.metricPrefixPlural,
"TimedOut",
props
);
return this.taskMetric(this.taskMetrics?.metricPrefixPlural, 'TimedOut', props);
}

/**
Expand All @@ -299,11 +277,7 @@ export abstract class TaskStateBase extends State implements INextable {
* @default - sum over 5 minutes
*/
public metricStarted(props?: cloudwatch.MetricOptions): cloudwatch.Metric {
return this.taskMetric(
this.taskMetrics?.metricPrefixPlural,
"Started",
props
);
return this.taskMetric(this.taskMetrics?.metricPrefixPlural, 'Started', props);
}

/**
Expand All @@ -312,11 +286,7 @@ export abstract class TaskStateBase extends State implements INextable {
* @default - sum over 5 minutes
*/
public metricSucceeded(props?: cloudwatch.MetricOptions): cloudwatch.Metric {
return this.taskMetric(
this.taskMetrics?.metricPrefixPlural,
"Succeeded",
props
);
return this.taskMetric(this.taskMetrics?.metricPrefixPlural, 'Succeeded', props);
}

/**
Expand All @@ -325,26 +295,16 @@ export abstract class TaskStateBase extends State implements INextable {
* @default - sum over 5 minutes
*/
public metricFailed(props?: cloudwatch.MetricOptions): cloudwatch.Metric {
return this.taskMetric(
this.taskMetrics?.metricPrefixPlural,
"Failed",
props
);
return this.taskMetric(this.taskMetrics?.metricPrefixPlural, 'Failed', props);
}

/**
* Metric for the number of times the heartbeat times out for this activity
*
* @default - sum over 5 minutes
*/
public metricHeartbeatTimedOut(
props?: cloudwatch.MetricOptions
): cloudwatch.Metric {
return this.taskMetric(
this.taskMetrics?.metricPrefixPlural,
"HeartbeatTimedOut",
props
);
public metricHeartbeatTimedOut(props?: cloudwatch.MetricOptions): cloudwatch.Metric {
return this.taskMetric(this.taskMetrics?.metricPrefixPlural, 'HeartbeatTimedOut', props);
}

protected whenBoundToGraph(graph: StateGraph) {
Expand All @@ -353,13 +313,11 @@ export abstract class TaskStateBase extends State implements INextable {
graph.registerPolicyStatement(policyStatement);
}
if (this.credentials) {
graph.registerPolicyStatement(
new iam.PolicyStatement({
effect: iam.Effect.ALLOW,
actions: ["sts:AssumeRole"],
resources: [this.credentials.role.resource],
})
);
graph.registerPolicyStatement(new iam.PolicyStatement({
effect: iam.Effect.ALLOW,
actions: ['sts:AssumeRole'],
resources: [this.credentials.role.resource],
}));
}
}

Expand All @@ -368,35 +326,24 @@ export abstract class TaskStateBase extends State implements INextable {
*/
protected abstract _renderTask(): any;

private taskMetric(
prefix: string | undefined,
suffix: string,
props?: cloudwatch.MetricOptions
): cloudwatch.Metric {
private taskMetric(prefix: string | undefined, suffix: string, props?: cloudwatch.MetricOptions): cloudwatch.Metric {
if (prefix === undefined) {
throw new Error(
"Task does not expose metrics. Use the 'metric()' function to add metrics."
);
throw new Error('Task does not expose metrics. Use the \'metric()\' function to add metrics.');
}
return this.metric(prefix + suffix, props);
}

private renderCredentials() {
return this.credentials
? FieldUtils.renderObject({
Credentials: { RoleArn: this.credentials.role.roleArn },
})
: undefined;
return this.credentials ? FieldUtils.renderObject({ Credentials: { RoleArn: this.credentials.role.roleArn } }) : undefined;
}

private renderTaskBase() {
return {
Type: "Task",
Type: 'Task',
Comment: this.comment,
TimeoutSeconds: this.timeout?.toSeconds() ?? this.taskTimeout?.seconds,
TimeoutSecondsPath: this.taskTimeout?.path,
HeartbeatSeconds:
this.heartbeat?.toSeconds() ?? this.heartbeatTimeout?.seconds,
HeartbeatSeconds: this.heartbeat?.toSeconds() ?? this.heartbeatTimeout?.seconds,
HeartbeatSecondsPath: this.heartbeatTimeout?.path,
InputPath: renderJsonPath(this.inputPath),
OutputPath: renderJsonPath(this.outputPath),
Expand Down Expand Up @@ -447,22 +394,22 @@ export enum IntegrationPattern {
*
* @see https://docs.aws.amazon.com/step-functions/latest/dg/connect-to-resource.html#connect-default
*/
REQUEST_RESPONSE = "REQUEST_RESPONSE",
REQUEST_RESPONSE = 'REQUEST_RESPONSE',

/**
* Step Functions can wait for a request to complete before progressing to the next state.
*
* @see https://docs.aws.amazon.com/step-functions/latest/dg/connect-to-resource.html#connect-sync
*/
RUN_JOB = "RUN_JOB",
RUN_JOB = 'RUN_JOB',

/**
* Callback tasks provide a way to pause a workflow until a task token is returned.
* You must set a task token when using the callback pattern
*
* @see https://docs.aws.amazon.com/step-functions/latest/dg/connect-to-resource.html#connect-wait-token
*/
WAIT_FOR_TASK_TOKEN = "WAIT_FOR_TASK_TOKEN",
WAIT_FOR_TASK_TOKEN = 'WAIT_FOR_TASK_TOKEN',
}

/**
Expand Down

0 comments on commit 9c5f521

Please sign in to comment.