@dontirun/state-machine-semaphore 0.1.239 → 0.1.241

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. package/.jsii +2 -2
  2. package/API.md +120 -0
  3. package/lib/index.js +1 -1
  4. package/package.json +3 -3
package/.jsii CHANGED
@@ -3308,6 +3308,6 @@
3308
3308
  "symbolId": "src/index:TableReadWriteCapacity"
3309
3309
  }
3310
3310
  },
3311
- "version": "0.1.239",
3312
- "fingerprint": "nR75levPebWNbklVznGzxIVlAkHWaInBcFBUb0MAgTU="
3311
+ "version": "0.1.241",
3312
+ "fingerprint": "38Rmryt1BB8FUd3E90oQpiSrgOc71UUtpqOH6xDHwt8="
3313
3313
  }
package/API.md CHANGED
@@ -1,3 +1,123 @@
1
+ # @dontirun/state-machine-semaphore
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@dontirun/state-machine-semaphore.svg)](https://img.shields.io/npm/v/@dontirun/state-machine-semaphore)
4
+ [![PyPI version](https://img.shields.io/pypi/v/state-machine-semaphore.svg)](https://pypi.org/project/state-machine-semaphore)
5
+ [![NuGet version](https://img.shields.io/nuget/v/Dontirun.StateMachineSemaphore)](https://www.nuget.org/packages/Dontirun.StateMachineSemaphore)
6
+ [![Maven version](https://img.shields.io/maven-central/v/io.github.dontirun/statemachinesemaphore)](https://search.maven.org/artifact/io.github.dontirun/statemachinesemaphore)
7
+ [![Go version](https://img.shields.io/github/go-mod/go-version/dontirun/state-machine-semaphore-go?color=orange&filename=dontirunstatemachinesemaphore%2Fgo.mod)](https://github.com/dontirun/state-machine-semaphore-go)
8
+
9
+ [![View on Construct Hub](https://constructs.dev/badge?package=%40dontirun%2Fstate-machine-semaphore)](https://constructs.dev/packages/@dontirun/state-machine-semaphore)
10
+
11
+ An [aws-cdk](https://github.com/aws/aws-cdk) construct that enables you to use AWS Step Functions to control concurrency in your distributed system. You can use this construct to distributed state machine semaphores to control concurrent invocations of contentious work.
12
+
13
+ This construct is based off of [Justin Callison's](https://github.com/JustinCallison) example [code](https://github.com/aws-samples/aws-stepfunctions-examples/blob/main/sam/app-control-concurrency-with-dynamodb/statemachines/dynamodb-semaphore.asl.json). Make sure to check out Justin's [blogpost](https://aws.amazon.com/blogs/compute/controlling-concurrency-in-distributed-systems-using-aws-step-functions/) to learn about how the system works.
14
+
15
+ ## Examples
16
+
17
+ ### Example 1) A state machine with a controlled job
18
+
19
+ <details>
20
+
21
+ <summary>Click to see code</summary>
22
+
23
+ ```typescript
24
+ import { Function } from 'aws-cdk-lib/aws-lambda';
25
+ import { Duration, Stack, StackProps } from 'aws-cdk-lib';
26
+ import { StateMachine, Succeed, Wait, WaitTime } from 'aws-cdk-lib/aws-stepfunctions';
27
+ import { LambdaInvoke } from 'aws-cdk-lib/aws-stepfunctions-tasks';
28
+ import { Construct } from 'constructs';
29
+ import { Semaphore } from '@dontirun/state-machine-semaphore';
30
+
31
+
32
+ export class CdkTestStack extends Stack {
33
+ constructor(scope: Construct, id: string, props?: StackProps) {
34
+ super(scope, id, props);
35
+
36
+ const contestedJob = new LambdaInvoke(this, 'ContestedJobPart1', {
37
+ lambdaFunction: Function.fromFunctionName(this, 'JobFunctionPart1', 'cool-function'),
38
+ }).next(new Wait(this, 'Wait', { time: WaitTime.duration(Duration.seconds(7)) }))
39
+ .next(new Wait(this, 'AnotherWait', { time: WaitTime.duration(Duration.seconds(7)) }))
40
+ .next(new Wait(this, 'YetAnotherWait', { time: WaitTime.duration(Duration.seconds(7)) }));
41
+
42
+ const afterContestedJob = new Succeed(this, 'Succeed');
43
+
44
+ const stateMachineFragment = new Semaphore(stack, 'Semaphore', { lockName: 'life', limit: 42, job: contestedJob, nextState: afterContestedJob });
45
+
46
+ new StateMachine(this, 'StateMachine', {
47
+ definition: stateMachineFragment,
48
+ });
49
+ }
50
+ }
51
+ ```
52
+
53
+ </details>
54
+
55
+
56
+ <details>
57
+
58
+ <summary>Click to see the state machine definition</summary>
59
+
60
+ ![Example 1 Definition](./images/Example1_Graph_Edit.png)
61
+ </details>
62
+
63
+
64
+ ### Example 2) A state machine with multiple semaphores
65
+
66
+ <details>
67
+
68
+ <summary>Click to see code</summary>
69
+
70
+ ```typescript
71
+ import { Function } from 'aws-cdk-lib/aws-lambda';
72
+ import { Duration, Stack, StackProps } from 'aws-cdk-lib';
73
+ import { StateMachine, Succeed, Wait, WaitTime } from 'aws-cdk-lib/aws-stepfunctions';
74
+ import { LambdaInvoke } from 'aws-cdk-lib/aws-stepfunctions-tasks';
75
+ import { Construct } from 'constructs';
76
+ import { Semaphore } from '@dontirun/state-machine-semaphore';
77
+
78
+
79
+ export class CdkTestStack extends Stack {
80
+ constructor(scope: Construct, id: string, props?: StackProps) {
81
+ super(scope, id, props);
82
+
83
+ const contestedJob = new LambdaInvoke(this, 'ContestedJobPart1', {
84
+ lambdaFunction: Function.fromFunctionName(this, 'JobFunctionPart1', 'cool-function'),
85
+ })
86
+ const notContestedJob = new LambdaInvoke(this, 'NotContestedJob', {
87
+ lambdaFunction: Function.fromFunctionName(this, 'NotContestedJobFunction', 'cooler-function'),
88
+ })
89
+ const contestedJob2 = new LambdaInvoke(this, 'ContestedJobPart2', {
90
+ lambdaFunction: Function.fromFunctionName(this, 'JobFunctionPart2', 'coolest-function'),
91
+ })
92
+ const afterContestedJob2 = new Succeed(this, 'Succeed');
93
+
94
+ const definition = new Semaphore(stack, 'Semaphore', { lockName: 'life', limit: 42, job: contestedJob, nextState: notContestedJob })
95
+ .next(new Semaphore(stack, 'Semaphore2', { lockName: 'liberty', limit: 7, job: contestedJob2, nextState: afterContestedJob2 }));
96
+
97
+ new StateMachine(this, 'StateMachine', {
98
+ definition: definition,
99
+ });
100
+ }
101
+ }
102
+ ```
103
+
104
+ </details>
105
+
106
+ <details>
107
+
108
+ <summary>Click to see the state machine definition</summary>
109
+
110
+ ![Example 2 Definition](./images/Example2_Graph_Edit.png)
111
+ </details>
112
+
113
+ ## API Reference
114
+
115
+ See [API.md](./API.md).
116
+
117
+ ## License
118
+
119
+ This project is licensed under the Apache-2.0 License.
120
+
1
121
  # API Reference <a name="API Reference" id="api-reference"></a>
2
122
 
3
123
  ## Constructs <a name="Constructs" id="Constructs"></a>
package/lib/index.js CHANGED
@@ -177,7 +177,7 @@ class Semaphore extends aws_stepfunctions_1.StateMachineFragment {
177
177
  }
178
178
  exports.Semaphore = Semaphore;
179
179
  _a = JSII_RTTI_SYMBOL_1;
180
- Semaphore[_a] = { fqn: "@dontirun/state-machine-semaphore.Semaphore", version: "0.1.239" };
180
+ Semaphore[_a] = { fqn: "@dontirun/state-machine-semaphore.Semaphore", version: "0.1.241" };
181
181
  /**
182
182
  * The names and associated concurrency limits and number of uses of the sempahores.
183
183
  */
package/package.json CHANGED
@@ -54,10 +54,10 @@
54
54
  "jest-junit": "^15",
55
55
  "jsii": "1.x",
56
56
  "jsii-diff": "^1.80.0",
57
- "jsii-docgen": "^7.1.46",
57
+ "jsii-docgen": "^7.2.1",
58
58
  "jsii-pacmak": "^1.80.0",
59
59
  "npm-check-updates": "^16",
60
- "projen": "^0.71.11",
60
+ "projen": "^0.71.16",
61
61
  "standard-version": "^9",
62
62
  "ts-jest": "^27",
63
63
  "typescript": "^4.9.5"
@@ -78,7 +78,7 @@
78
78
  ],
79
79
  "main": "lib/index.js",
80
80
  "license": "Apache-2.0",
81
- "version": "0.1.239",
81
+ "version": "0.1.241",
82
82
  "jest": {
83
83
  "testMatch": [
84
84
  "<rootDir>/src/**/__tests__/**/*.ts?(x)",