Skip to content

Commit

Permalink
Merge pull request #120 from skrud-dt/use-taskTimeout
Browse files Browse the repository at this point in the history
feat!: use taskTimeout in SempahoreTimeoutOptions
  • Loading branch information
flyingImer authored May 2, 2023
2 parents ff9a27a + b01f098 commit 3a5b809
Show file tree
Hide file tree
Showing 9 changed files with 222 additions and 46 deletions.
4 changes: 2 additions & 2 deletions .projen/deps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .projenrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const project = new awscdk.AwsCdkConstructLibrary({
author: 'Ej Wang',
authorAddress: '[email protected]',

cdkVersion: '2.10.0',
cdkVersion: '2.63.0',

autoApproveOptions: {
allowedUsernames: ['flyingImer'],
Expand Down
108 changes: 102 additions & 6 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -1012,6 +1012,7 @@ const acquireOptions: AcquireOptions = { ... }
| <code><a href="#cdk-concurrency-controller.AcquireOptions.property.name">name</a></code> | <code>string</code> | The name for the semaphore. |
| <code><a href="#cdk-concurrency-controller.AcquireOptions.property.userId">userId</a></code> | <code>string</code> | The semaphore user id to acquire/release resource usage. |
| <code><a href="#cdk-concurrency-controller.AcquireOptions.property.nextTryWaitTime">nextTryWaitTime</a></code> | <code>string</code> | Wait a fixed amount of time (in second) for another try to acquire semaphore if not acquired in previous tries. |
| <code><a href="#cdk-concurrency-controller.AcquireOptions.property.taskTimeout">taskTimeout</a></code> | <code>aws-cdk-lib.aws_stepfunctions.Timeout</code> | Maximum run time for the execution. |
| <code><a href="#cdk-concurrency-controller.AcquireOptions.property.timeout">timeout</a></code> | <code>aws-cdk-lib.Duration</code> | Maximum run time for the execution. |

---
Expand Down Expand Up @@ -1058,7 +1059,22 @@ Wait a fixed amount of time (in second) for another try to acquire semaphore if

---

##### `timeout`<sup>Optional</sup> <a name="timeout" id="cdk-concurrency-controller.AcquireOptions.property.timeout"></a>
##### `taskTimeout`<sup>Optional</sup> <a name="taskTimeout" id="cdk-concurrency-controller.AcquireOptions.property.taskTimeout"></a>

```typescript
public readonly taskTimeout: Timeout;
```

- *Type:* aws-cdk-lib.aws_stepfunctions.Timeout
- *Default:* No timeout

Maximum run time for the execution.

---

##### ~~`timeout`~~<sup>Optional</sup> <a name="timeout" id="cdk-concurrency-controller.AcquireOptions.property.timeout"></a>

- *Deprecated:* Use taskTimeout instead

```typescript
public readonly timeout: Duration;
Expand Down Expand Up @@ -1312,13 +1328,29 @@ const acquireViaStartExecutionFragmentProps: AcquireViaStartExecutionFragmentPro

| **Name** | **Type** | **Description** |
| --- | --- | --- |
| <code><a href="#cdk-concurrency-controller.AcquireViaStartExecutionFragmentProps.property.taskTimeout">taskTimeout</a></code> | <code>aws-cdk-lib.aws_stepfunctions.Timeout</code> | Maximum run time for the execution. |
| <code><a href="#cdk-concurrency-controller.AcquireViaStartExecutionFragmentProps.property.timeout">timeout</a></code> | <code>aws-cdk-lib.Duration</code> | Maximum run time for the execution. |
| <code><a href="#cdk-concurrency-controller.AcquireViaStartExecutionFragmentProps.property.input">input</a></code> | <code><a href="#cdk-concurrency-controller.AcquireSemaphoreTaskInput">AcquireSemaphoreTaskInput</a></code> | *No description.* |
| <code><a href="#cdk-concurrency-controller.AcquireViaStartExecutionFragmentProps.property.stateMachine">stateMachine</a></code> | <code>aws-cdk-lib.aws_stepfunctions.IStateMachine</code> | The Step Functions state machine to start the execution on. |

---

##### `timeout`<sup>Optional</sup> <a name="timeout" id="cdk-concurrency-controller.AcquireViaStartExecutionFragmentProps.property.timeout"></a>
##### `taskTimeout`<sup>Optional</sup> <a name="taskTimeout" id="cdk-concurrency-controller.AcquireViaStartExecutionFragmentProps.property.taskTimeout"></a>

```typescript
public readonly taskTimeout: Timeout;
```

- *Type:* aws-cdk-lib.aws_stepfunctions.Timeout
- *Default:* No timeout

Maximum run time for the execution.

---

##### ~~`timeout`~~<sup>Optional</sup> <a name="timeout" id="cdk-concurrency-controller.AcquireViaStartExecutionFragmentProps.property.timeout"></a>

- *Deprecated:* Use taskTimeout instead

```typescript
public readonly timeout: Duration;
Expand Down Expand Up @@ -1450,6 +1482,7 @@ const releaseOptions: ReleaseOptions = { ... }
| <code><a href="#cdk-concurrency-controller.ReleaseOptions.property.name">name</a></code> | <code>string</code> | The name for the semaphore. |
| <code><a href="#cdk-concurrency-controller.ReleaseOptions.property.userId">userId</a></code> | <code>string</code> | The semaphore user id to acquire/release resource usage. |
| <code><a href="#cdk-concurrency-controller.ReleaseOptions.property.checkSemaphoreUseFirst">checkSemaphoreUseFirst</a></code> | <code>boolean</code> | Check if the semaphore use exists before trying to release it. |
| <code><a href="#cdk-concurrency-controller.ReleaseOptions.property.taskTimeout">taskTimeout</a></code> | <code>aws-cdk-lib.aws_stepfunctions.Timeout</code> | Maximum run time for the execution. |
| <code><a href="#cdk-concurrency-controller.ReleaseOptions.property.timeout">timeout</a></code> | <code>aws-cdk-lib.Duration</code> | Maximum run time for the execution. |

---
Expand Down Expand Up @@ -1501,7 +1534,22 @@ see more about hot partition: https://aws.amazon.com/premiumsupport/knowledge-ce

---

##### `timeout`<sup>Optional</sup> <a name="timeout" id="cdk-concurrency-controller.ReleaseOptions.property.timeout"></a>
##### `taskTimeout`<sup>Optional</sup> <a name="taskTimeout" id="cdk-concurrency-controller.ReleaseOptions.property.taskTimeout"></a>

```typescript
public readonly taskTimeout: Timeout;
```

- *Type:* aws-cdk-lib.aws_stepfunctions.Timeout
- *Default:* No timeout

Maximum run time for the execution.

---

##### ~~`timeout`~~<sup>Optional</sup> <a name="timeout" id="cdk-concurrency-controller.ReleaseOptions.property.timeout"></a>

- *Deprecated:* Use taskTimeout instead

```typescript
public readonly timeout: Duration;
Expand Down Expand Up @@ -1730,13 +1778,29 @@ const releaseViaStartExecutionFragmentProps: ReleaseViaStartExecutionFragmentPro

| **Name** | **Type** | **Description** |
| --- | --- | --- |
| <code><a href="#cdk-concurrency-controller.ReleaseViaStartExecutionFragmentProps.property.taskTimeout">taskTimeout</a></code> | <code>aws-cdk-lib.aws_stepfunctions.Timeout</code> | Maximum run time for the execution. |
| <code><a href="#cdk-concurrency-controller.ReleaseViaStartExecutionFragmentProps.property.timeout">timeout</a></code> | <code>aws-cdk-lib.Duration</code> | Maximum run time for the execution. |
| <code><a href="#cdk-concurrency-controller.ReleaseViaStartExecutionFragmentProps.property.input">input</a></code> | <code><a href="#cdk-concurrency-controller.ReleaseSemaphoreTaskInput">ReleaseSemaphoreTaskInput</a></code> | *No description.* |
| <code><a href="#cdk-concurrency-controller.ReleaseViaStartExecutionFragmentProps.property.stateMachine">stateMachine</a></code> | <code>aws-cdk-lib.aws_stepfunctions.IStateMachine</code> | The Step Functions state machine to start the execution on. |

---

##### `timeout`<sup>Optional</sup> <a name="timeout" id="cdk-concurrency-controller.ReleaseViaStartExecutionFragmentProps.property.timeout"></a>
##### `taskTimeout`<sup>Optional</sup> <a name="taskTimeout" id="cdk-concurrency-controller.ReleaseViaStartExecutionFragmentProps.property.taskTimeout"></a>

```typescript
public readonly taskTimeout: Timeout;
```

- *Type:* aws-cdk-lib.aws_stepfunctions.Timeout
- *Default:* No timeout

Maximum run time for the execution.

---

##### ~~`timeout`~~<sup>Optional</sup> <a name="timeout" id="cdk-concurrency-controller.ReleaseViaStartExecutionFragmentProps.property.timeout"></a>

- *Deprecated:* Use taskTimeout instead

```typescript
public readonly timeout: Duration;
Expand Down Expand Up @@ -1833,13 +1897,29 @@ const semaphoreStateMachineProps: SemaphoreStateMachineProps = { ... }

| **Name** | **Type** | **Description** |
| --- | --- | --- |
| <code><a href="#cdk-concurrency-controller.SemaphoreStateMachineProps.property.taskTimeout">taskTimeout</a></code> | <code>aws-cdk-lib.aws_stepfunctions.Timeout</code> | Maximum run time for the execution. |
| <code><a href="#cdk-concurrency-controller.SemaphoreStateMachineProps.property.timeout">timeout</a></code> | <code>aws-cdk-lib.Duration</code> | Maximum run time for the execution. |
| <code><a href="#cdk-concurrency-controller.SemaphoreStateMachineProps.property.logs">logs</a></code> | <code>aws-cdk-lib.aws_stepfunctions.LogOptions</code> | Defines what execution history events are logged and where they are logged. |
| <code><a href="#cdk-concurrency-controller.SemaphoreStateMachineProps.property.tracingEnabled">tracingEnabled</a></code> | <code>boolean</code> | Specifies whether Amazon X-Ray tracing is enabled for this state machine. |

---

##### `timeout`<sup>Optional</sup> <a name="timeout" id="cdk-concurrency-controller.SemaphoreStateMachineProps.property.timeout"></a>
##### `taskTimeout`<sup>Optional</sup> <a name="taskTimeout" id="cdk-concurrency-controller.SemaphoreStateMachineProps.property.taskTimeout"></a>

```typescript
public readonly taskTimeout: Timeout;
```

- *Type:* aws-cdk-lib.aws_stepfunctions.Timeout
- *Default:* No timeout

Maximum run time for the execution.

---

##### ~~`timeout`~~<sup>Optional</sup> <a name="timeout" id="cdk-concurrency-controller.SemaphoreStateMachineProps.property.timeout"></a>

- *Deprecated:* Use taskTimeout instead

```typescript
public readonly timeout: Duration;
Expand Down Expand Up @@ -1944,11 +2024,27 @@ const semaphoreTimeoutOptions: SemaphoreTimeoutOptions = { ... }

| **Name** | **Type** | **Description** |
| --- | --- | --- |
| <code><a href="#cdk-concurrency-controller.SemaphoreTimeoutOptions.property.taskTimeout">taskTimeout</a></code> | <code>aws-cdk-lib.aws_stepfunctions.Timeout</code> | Maximum run time for the execution. |
| <code><a href="#cdk-concurrency-controller.SemaphoreTimeoutOptions.property.timeout">timeout</a></code> | <code>aws-cdk-lib.Duration</code> | Maximum run time for the execution. |

---

##### `timeout`<sup>Optional</sup> <a name="timeout" id="cdk-concurrency-controller.SemaphoreTimeoutOptions.property.timeout"></a>
##### `taskTimeout`<sup>Optional</sup> <a name="taskTimeout" id="cdk-concurrency-controller.SemaphoreTimeoutOptions.property.taskTimeout"></a>

```typescript
public readonly taskTimeout: Timeout;
```

- *Type:* aws-cdk-lib.aws_stepfunctions.Timeout
- *Default:* No timeout

Maximum run time for the execution.

---

##### ~~`timeout`~~<sup>Optional</sup> <a name="timeout" id="cdk-concurrency-controller.SemaphoreTimeoutOptions.property.timeout"></a>

- *Deprecated:* Use taskTimeout instead

```typescript
public readonly timeout: Duration;
Expand Down
6 changes: 3 additions & 3 deletions package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 20 additions & 18 deletions src/fragments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@ import { Attribute, AttributeType, ITable } from 'aws-cdk-lib/aws-dynamodb';
import { Choice, Condition, Errors, IChainable, INextable, IntegrationPattern, IStateMachine, JsonPath, Pass, RetryProps, State, StateMachineFragment, TaskInput, Wait, WaitTime } from 'aws-cdk-lib/aws-stepfunctions';
import { DynamoAttributeValue, DynamoGetItem, DynamoProjectionExpression, DynamoPutItem, DynamoReturnValues, DynamoUpdateItem, StepFunctionsStartExecution } from 'aws-cdk-lib/aws-stepfunctions-tasks';
import { Construct } from 'constructs';
import { isDeterminedNonNegativeInteger } from './private/utils';
import { SemaphoreTimeoutOptions } from './private/types';
import { isDeterminedNonNegativeInteger, toTaskTimeout } from './private/utils';

// Re-export SemaphoreTimeoutOptions - since this type is needed in ./private/utils,
// it would have created a circular dependency to have ./private/utils depend on fragments.ts.
// Definiting it in ./private/types and then re-exporting it makes it easier to further export via JSII
// without adding a new entry there.
export { SemaphoreTimeoutOptions } from './private/types';

export interface SemaphoreTableDefinition {
readonly table: ITable;
Expand Down Expand Up @@ -379,15 +386,6 @@ class CheckIfSemaphoreUsedByUserFragment extends StateMachineFragment {
}
}

export interface SemaphoreTimeoutOptions {
/**
* Maximum run time for the execution.
*
* @default No timeout
*/
readonly timeout?: Duration;
}

interface SemaphoreTaskCommonInput {
readonly name: string;
readonly userId: string;
Expand Down Expand Up @@ -422,7 +420,7 @@ export class AcquireViaStartExecutionFragment extends StateMachineFragment {
integrationPattern: IntegrationPattern.RUN_JOB,
associateWithParent: true,
input: TaskInput.fromObject(props.input),
timeout: props.timeout,
taskTimeout: toTaskTimeout(props),
});
this.endStates = this.startState.endStates;
}
Expand All @@ -438,13 +436,17 @@ export class ReleaseViaStartExecutionFragment extends StateMachineFragment {

constructor(scope: Construct, id: string, props: ReleaseViaStartExecutionFragmentProps) {
super(scope, id);
this.startState = new StepFunctionsStartExecution(this, 'ReleaseSemaphoreViaStartExecution', {
stateMachine: props.stateMachine,
integrationPattern: IntegrationPattern.RUN_JOB,
associateWithParent: true,
input: TaskInput.fromObject(props.input),
timeout: props.timeout,
});
this.startState = new StepFunctionsStartExecution(
this,
'ReleaseSemaphoreViaStartExecution',
{
stateMachine: props.stateMachine,
integrationPattern: IntegrationPattern.RUN_JOB,
associateWithParent: true,
input: TaskInput.fromObject(props.input),
taskTimeout: toTaskTimeout(props),
},
);
this.endStates = this.startState.endStates;
}
}
17 changes: 17 additions & 0 deletions src/private/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Duration } from 'aws-cdk-lib';
import { Timeout } from 'aws-cdk-lib/aws-stepfunctions';

export interface SemaphoreTimeoutOptions {
/**
* Maximum run time for the execution.
*
* @deprecated Use taskTimeout instead
* @default No timeout
*/
readonly timeout?: Duration;
/**
* Maximum run time for the execution.
* @default No timeout
*/
readonly taskTimeout?: Timeout;
}
15 changes: 13 additions & 2 deletions src/private/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { isPositiveInteger, JsonPath } from 'aws-cdk-lib/aws-stepfunctions';
import { isPositiveInteger, JsonPath, Timeout } from 'aws-cdk-lib/aws-stepfunctions';
import { SemaphoreTimeoutOptions } from './types';

/**
* Check if the given literal string is a non negative integer value at compile time.
Expand All @@ -11,4 +12,14 @@ export const isDeterminedNonNegativeInteger = (value: string): boolean => {
}
const num = new Number(value);
return !Number.isNaN(num) && isPositiveInteger(num.valueOf());
};
};

/**
* As of [email protected], `timeout` is a deprecated parameter
* and we should be using taskTimeout instead.
*
* @param props SemaphoreTimeoutOptions
* @returns A value for `taskTimeout`
*/
export const toTaskTimeout = ({ taskTimeout, timeout }: SemaphoreTimeoutOptions): undefined | Timeout =>
taskTimeout ?? (timeout ? Timeout.duration(timeout) : undefined);
Loading

0 comments on commit 3a5b809

Please sign in to comment.