@dontirun/state-machine-semaphore 0.0.1 → 0.1.2

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.
package/.gitattributes CHANGED
@@ -16,6 +16,7 @@
16
16
  /.projen/deps.json linguist-generated
17
17
  /.projen/files.json linguist-generated
18
18
  /.projen/tasks.json linguist-generated
19
+ /API.md linguist-generated
19
20
  /LICENSE linguist-generated
20
21
  /package.json linguist-generated
21
22
  /tsconfig.dev.json linguist-generated
package/.jsii CHANGED
@@ -2989,7 +2989,7 @@
2989
2989
  },
2990
2990
  "name": "@dontirun/state-machine-semaphore",
2991
2991
  "readme": {
2992
- "markdown": "# @dontirun/state-machine-semaphore\n\n[![npm version](https://img.shields.io/npm/v/donti/state-machine-semaphore.svg)](https://www.npmjs.com/package/@donti%2Fstate-machine-semaphore)\n[![PyPI version](https://img.shields.io/pypi/v/state-machine-semaphore.svg)](https://pypi.org/project/state-machine-semaphore)\n[![NuGet version](https://img.shields.io/nuget/v/Dontirun.StateMachineSemaphore)](https://www.nuget.org/packages/Dontirun.StateMachineSemaphore)\n\n[![View on Construct Hub](https://constructs.dev/badge?package=%40dontirun%2Fstate-machine-semaphore)](https://constructs.dev/packages/@dontirun/state-machine-semaphore)\n\nAn [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.\n\nThis 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.\n\n## Examples\n\n### Example 1) A state machine with a controlled job\n\n<table>\n<tr>\n<th>Code</th>\n<th>Definition</th>\n</tr>\n<tr>\n<td>\n\n```typescript\nimport { Function } from 'aws-cdk-lib/aws-lambda';\nimport { Duration, Stack, StackProps } from 'aws-cdk-lib';\nimport { StateMachine, Succeed, Wait, WaitTime } from 'aws-cdk-lib/aws-stepfunctions';\nimport { LambdaInvoke } from 'aws-cdk-lib/aws-stepfunctions-tasks';\nimport { Construct } from 'constructs';\nimport { SemaphoreGenerator } from '@dontirun/state-machine-semaphore';\n\n\nexport class CdkTestStack extends Stack {\n constructor(scope: Construct, id: string, props?: StackProps) {\n super(scope, id, props);\n\n const contestedJob = new LambdaInvoke(this, 'ContestedJobPart1', {\n lambdaFunction: Function.fromFunctionName(this, 'JobFunctionPart1', 'cool-function'),\n }).next(new Wait(this, 'Wait', { time: WaitTime.duration(Duration.seconds(7)) }))\n .next(new Wait(this, 'AnotherWait', { time: WaitTime.duration(Duration.seconds(7)) }))\n .next(new Wait(this, 'YetAnotherWait', { time: WaitTime.duration(Duration.seconds(7)) }));\n\n const afterContestedJob = new Succeed(this, 'Succeed');\n\n const generator = new SemaphoreGenerator(this, 'SemaphoreGenerator');\n const stateMachineFragment = generator.generateSemaphoredJob('life', 42, contestedJob, afterContestedJob);\n\n new StateMachine(this, 'StateMachine', {\n definition: stateMachineFragment,\n });\n }\n}\n```\n\n</td>\n<td>\n\n![Example 1 Definition](./images/Example1_Graph_Edit.png)\n</td>\n</tr>\n</table>\n\n### Example 2) A state machine with multiple semaphores\n\n<table>\n<tr>\n<th>Code</th>\n<th>Definition</th>\n</tr>\n<tr>\n<td>\n\n```typescript\nimport { Function } from 'aws-cdk-lib/aws-lambda';\nimport { Duration, Stack, StackProps } from 'aws-cdk-lib';\nimport { StateMachine, Succeed, Wait, WaitTime } from 'aws-cdk-lib/aws-stepfunctions';\nimport { LambdaInvoke } from 'aws-cdk-lib/aws-stepfunctions-tasks';\nimport { Construct } from 'constructs';\nimport { SemaphoreGenerator } from '@dontirun/state-machine-semaphore';\n\n\nexport class CdkTestStack extends Stack {\n constructor(scope: Construct, id: string, props?: StackProps) {\n super(scope, id, props);\n\n const contestedJob = new LambdaInvoke(this, 'ContestedJobPart1', {\n lambdaFunction: Function.fromFunctionName(this, 'JobFunctionPart1', 'cool-function'),\n })\n const notContestedJob = new LambdaInvoke(this, 'NotContestedJob', {\n lambdaFunction: Function.fromFunctionName(this, 'NotContestedJobFunction', 'cooler-function'),\n })\n const contestedJob2 = new LambdaInvoke(this, 'ContestedJobPart2', {\n lambdaFunction: Function.fromFunctionName(this, 'JobFunctionPart2', 'coolest-function'),\n })\n const afterContestedJob2 = new Succeed(this, 'Succeed');\n\n const generator = new SemaphoreGenerator(this, 'SemaphoreGenerator');\n const stateMachineFragment = generator.generateSemaphoredJob('life', 42, contestedJob, notContestedJob);\n const stateMachineFragment2 = generator.generateSemaphoredJob('liberty', 7, contestedJob2, afterContestedJob2);\n\n new StateMachine(this, 'StateMachine', {\n definition: stateMachineFragment.next(stateMachineFragment2),\n });\n }\n}\n```\n\n</td>\n<td>\n\n![Example 2 Definition](./images/Example2_Graph_Edit.png)\n</td>\n</tr>\n</table>\n\n## API Reference\n\nSee [API.md](./API.md).\n\n## License\n\nThis project is licensed under the Apache-2.0 License.\n"
2992
+ "markdown": "# @dontirun/state-machine-semaphore\n\n[![npm version](https://img.shields.io/npm/v/@dontirun/state-machine-semaphore.svg)](https://img.shields.io/npm/v/@dontirun/state-machine-semaphore)\n[![PyPI version](https://img.shields.io/pypi/v/state-machine-semaphore.svg)](https://pypi.org/project/state-machine-semaphore)\n[![NuGet version](https://img.shields.io/nuget/v/Dontirun.StateMachineSemaphore)](https://www.nuget.org/packages/Dontirun.StateMachineSemaphore)\n\n[![View on Construct Hub](https://constructs.dev/badge?package=%40dontirun%2Fstate-machine-semaphore)](https://constructs.dev/packages/@dontirun/state-machine-semaphore)\n\nAn [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.\n\nThis 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.\n\n## Examples\n\n### Example 1) A state machine with a controlled job\n\n<details>\n\n<summary>Click to see code</summary>\n\n```typescript\nimport { Function } from 'aws-cdk-lib/aws-lambda';\nimport { Duration, Stack, StackProps } from 'aws-cdk-lib';\nimport { StateMachine, Succeed, Wait, WaitTime } from 'aws-cdk-lib/aws-stepfunctions';\nimport { LambdaInvoke } from 'aws-cdk-lib/aws-stepfunctions-tasks';\nimport { Construct } from 'constructs';\nimport { Semaphore } from '@dontirun/state-machine-semaphore';\n\n\nexport class CdkTestStack extends Stack {\n constructor(scope: Construct, id: string, props?: StackProps) {\n super(scope, id, props);\n\n const contestedJob = new LambdaInvoke(this, 'ContestedJobPart1', {\n lambdaFunction: Function.fromFunctionName(this, 'JobFunctionPart1', 'cool-function'),\n }).next(new Wait(this, 'Wait', { time: WaitTime.duration(Duration.seconds(7)) }))\n .next(new Wait(this, 'AnotherWait', { time: WaitTime.duration(Duration.seconds(7)) }))\n .next(new Wait(this, 'YetAnotherWait', { time: WaitTime.duration(Duration.seconds(7)) }));\n\n const afterContestedJob = new Succeed(this, 'Succeed');\n\n const stateMachineFragment = new Semaphore(stack, 'Semaphore', { lockName: 'life', limit: 42, job: contestedJob, nextState: afterContestedJob });\n\n new StateMachine(this, 'StateMachine', {\n definition: stateMachineFragment,\n });\n }\n}\n```\n\n</details>\n\n\n<details>\n\n<summary>Click to see the state machine definition</summary>\n\n![Example 1 Definition](./images/Example1_Graph_Edit.png)\n</details>\n\n\n### Example 2) A state machine with multiple semaphores\n\n<details>\n\n<summary>Click to see code</summary>\n\n```typescript\nimport { Function } from 'aws-cdk-lib/aws-lambda';\nimport { Duration, Stack, StackProps } from 'aws-cdk-lib';\nimport { StateMachine, Succeed, Wait, WaitTime } from 'aws-cdk-lib/aws-stepfunctions';\nimport { LambdaInvoke } from 'aws-cdk-lib/aws-stepfunctions-tasks';\nimport { Construct } from 'constructs';\nimport { Semaphore } from '@dontirun/state-machine-semaphore';\n\n\nexport class CdkTestStack extends Stack {\n constructor(scope: Construct, id: string, props?: StackProps) {\n super(scope, id, props);\n\n const contestedJob = new LambdaInvoke(this, 'ContestedJobPart1', {\n lambdaFunction: Function.fromFunctionName(this, 'JobFunctionPart1', 'cool-function'),\n })\n const notContestedJob = new LambdaInvoke(this, 'NotContestedJob', {\n lambdaFunction: Function.fromFunctionName(this, 'NotContestedJobFunction', 'cooler-function'),\n })\n const contestedJob2 = new LambdaInvoke(this, 'ContestedJobPart2', {\n lambdaFunction: Function.fromFunctionName(this, 'JobFunctionPart2', 'coolest-function'),\n })\n const afterContestedJob2 = new Succeed(this, 'Succeed');\n\n const definition = new Semaphore(stack, 'Semaphore', { lockName: 'life', limit: 42, job: contestedJob, nextState: notContestedJob })\n .next(new Semaphore(stack, 'Semaphore2', { lockName: 'liberty', limit: 7, job: contestedJob2, nextState: afterContestedJob2 }));\n\n new StateMachine(this, 'StateMachine', {\n definition: definition,\n });\n }\n}\n```\n\n</details>\n\n<details>\n\n<summary>Click to see the state machine definition</summary>\n\n![Example 2 Definition](./images/Example2_Graph_Edit.png)\n</details>\n\n## API Reference\n\nSee [API.md](./API.md).\n\n## License\n\nThis project is licensed under the Apache-2.0 License.\n"
2993
2993
  },
2994
2994
  "repository": {
2995
2995
  "type": "git",
@@ -3023,27 +3023,26 @@
3023
3023
  "kind": "interface",
3024
3024
  "locationInModule": {
3025
3025
  "filename": "src/index.ts",
3026
- "line": 31
3026
+ "line": 57
3027
3027
  },
3028
3028
  "name": "IChainNextable",
3029
3029
  "symbolId": "src/index:IChainNextable"
3030
3030
  },
3031
- "@dontirun/state-machine-semaphore.SemaphoreGenerator": {
3031
+ "@dontirun/state-machine-semaphore.Semaphore": {
3032
3032
  "assembly": "@dontirun/state-machine-semaphore",
3033
- "base": "constructs.Construct",
3033
+ "base": "aws-cdk-lib.aws_stepfunctions.StateMachineFragment",
3034
3034
  "docs": {
3035
- "remarks": "Call `generateSemaphoredJob` to generate semaphored jobs.",
3036
3035
  "stability": "stable",
3037
- "summary": "Sets up up the DynamoDB table that stores the State Machine semaphores."
3036
+ "summary": "Generates a semaphore for a StepFunction job (or chained set of jobs) to limit parallelism across executions."
3038
3037
  },
3039
- "fqn": "@dontirun/state-machine-semaphore.SemaphoreGenerator",
3038
+ "fqn": "@dontirun/state-machine-semaphore.Semaphore",
3040
3039
  "initializer": {
3041
3040
  "docs": {
3042
3041
  "stability": "stable"
3043
3042
  },
3044
3043
  "locationInModule": {
3045
3044
  "filename": "src/index.ts",
3046
- "line": 49
3045
+ "line": 83
3047
3046
  },
3048
3047
  "parameters": [
3049
3048
  {
@@ -3060,9 +3059,8 @@
3060
3059
  },
3061
3060
  {
3062
3061
  "name": "props",
3063
- "optional": true,
3064
3062
  "type": {
3065
- "fqn": "@dontirun/state-machine-semaphore.SemaphoreGeneratorProps"
3063
+ "fqn": "@dontirun/state-machine-semaphore.SemaphoreProps"
3066
3064
  }
3067
3065
  }
3068
3066
  ]
@@ -3070,116 +3068,177 @@
3070
3068
  "kind": "class",
3071
3069
  "locationInModule": {
3072
3070
  "filename": "src/index.ts",
3073
- "line": 37
3071
+ "line": 63
3074
3072
  },
3075
- "methods": [
3073
+ "name": "Semaphore",
3074
+ "properties": [
3076
3075
  {
3077
3076
  "docs": {
3078
- "returns": "A StateMachineFragment that can chained to other states in the State Machine.",
3079
3077
  "stability": "stable",
3080
- "summary": "Generates a semaphore for a StepFunction job (or chained set of jobs) to limit parallelism across executions."
3078
+ "summary": "The states to chain onto if this fragment is used."
3081
3079
  },
3080
+ "immutable": true,
3082
3081
  "locationInModule": {
3083
3082
  "filename": "src/index.ts",
3084
- "line": 73
3083
+ "line": 80
3085
3084
  },
3086
- "name": "generateSemaphoredJob",
3087
- "parameters": [
3088
- {
3089
- "docs": {
3090
- "summary": "The name of the semaphore."
3091
- },
3092
- "name": "lockName",
3093
- "type": {
3094
- "primitive": "string"
3095
- }
3096
- },
3097
- {
3098
- "docs": {
3099
- "summary": "The maximum number of concurrent executions for the given lock."
3100
- },
3101
- "name": "limit",
3102
- "type": {
3103
- "primitive": "number"
3104
- }
3105
- },
3106
- {
3107
- "docs": {
3108
- "summary": "The job (or chained jobs) to be semaphored."
3109
- },
3110
- "name": "job",
3111
- "type": {
3112
- "fqn": "@dontirun/state-machine-semaphore.IChainNextable"
3113
- }
3114
- },
3115
- {
3116
- "docs": {
3117
- "summary": "The State to go to after the semaphored job completes."
3118
- },
3119
- "name": "nextState",
3120
- "type": {
3121
- "fqn": "aws-cdk-lib.aws_stepfunctions.State"
3122
- }
3123
- },
3124
- {
3125
- "docs": {
3126
- "remarks": "Throws an error if a different `limit` is specified. Default: false.",
3127
- "summary": "Explicility allow the reuse of a named lock from a previously generated job."
3128
- },
3129
- "name": "reuseLock",
3130
- "optional": true,
3131
- "type": {
3132
- "primitive": "boolean"
3133
- }
3134
- },
3135
- {
3136
- "docs": {
3137
- "remarks": "Significantly increases CloudFormation template size. Default: false.",
3138
- "summary": "Adds detailed comments to lock related states."
3085
+ "name": "endStates",
3086
+ "overrides": "aws-cdk-lib.aws_stepfunctions.StateMachineFragment",
3087
+ "type": {
3088
+ "collection": {
3089
+ "elementtype": {
3090
+ "fqn": "aws-cdk-lib.aws_stepfunctions.INextable"
3139
3091
  },
3140
- "name": "comments",
3141
- "optional": true,
3142
- "type": {
3143
- "primitive": "boolean"
3144
- }
3145
- }
3146
- ],
3147
- "returns": {
3148
- "type": {
3149
- "fqn": "aws-cdk-lib.aws_stepfunctions.StateMachineFragment"
3092
+ "kind": "array"
3150
3093
  }
3151
3094
  }
3095
+ },
3096
+ {
3097
+ "docs": {
3098
+ "stability": "stable",
3099
+ "summary": "The start state of this state machine fragment."
3100
+ },
3101
+ "immutable": true,
3102
+ "locationInModule": {
3103
+ "filename": "src/index.ts",
3104
+ "line": 79
3105
+ },
3106
+ "name": "startState",
3107
+ "overrides": "aws-cdk-lib.aws_stepfunctions.StateMachineFragment",
3108
+ "type": {
3109
+ "fqn": "aws-cdk-lib.aws_stepfunctions.State"
3110
+ }
3152
3111
  }
3153
3112
  ],
3154
- "name": "SemaphoreGenerator",
3155
- "symbolId": "src/index:SemaphoreGenerator"
3113
+ "symbolId": "src/index:Semaphore"
3156
3114
  },
3157
- "@dontirun/state-machine-semaphore.SemaphoreGeneratorProps": {
3115
+ "@dontirun/state-machine-semaphore.SemaphoreProps": {
3158
3116
  "assembly": "@dontirun/state-machine-semaphore",
3159
3117
  "datatype": true,
3160
3118
  "docs": {
3161
3119
  "stability": "stable",
3162
- "summary": "Interface for creating a SemaphoreGenerator."
3120
+ "summary": "Interface for creating a Semaphore."
3163
3121
  },
3164
- "fqn": "@dontirun/state-machine-semaphore.SemaphoreGeneratorProps",
3122
+ "fqn": "@dontirun/state-machine-semaphore.SemaphoreProps",
3165
3123
  "kind": "interface",
3166
3124
  "locationInModule": {
3167
3125
  "filename": "src/index.ts",
3168
- "line": 10
3126
+ "line": 11
3169
3127
  },
3170
- "name": "SemaphoreGeneratorProps",
3128
+ "name": "SemaphoreProps",
3171
3129
  "properties": [
3130
+ {
3131
+ "abstract": true,
3132
+ "docs": {
3133
+ "stability": "stable",
3134
+ "summary": "The job (or chained jobs) to be semaphored."
3135
+ },
3136
+ "immutable": true,
3137
+ "locationInModule": {
3138
+ "filename": "src/index.ts",
3139
+ "line": 23
3140
+ },
3141
+ "name": "job",
3142
+ "type": {
3143
+ "fqn": "@dontirun/state-machine-semaphore.IChainNextable"
3144
+ }
3145
+ },
3146
+ {
3147
+ "abstract": true,
3148
+ "docs": {
3149
+ "stability": "stable",
3150
+ "summary": "The maximum number of concurrent executions for the given lock."
3151
+ },
3152
+ "immutable": true,
3153
+ "locationInModule": {
3154
+ "filename": "src/index.ts",
3155
+ "line": 19
3156
+ },
3157
+ "name": "limit",
3158
+ "type": {
3159
+ "primitive": "number"
3160
+ }
3161
+ },
3162
+ {
3163
+ "abstract": true,
3164
+ "docs": {
3165
+ "stability": "stable",
3166
+ "summary": "The name of the semaphore."
3167
+ },
3168
+ "immutable": true,
3169
+ "locationInModule": {
3170
+ "filename": "src/index.ts",
3171
+ "line": 15
3172
+ },
3173
+ "name": "lockName",
3174
+ "type": {
3175
+ "primitive": "string"
3176
+ }
3177
+ },
3178
+ {
3179
+ "abstract": true,
3180
+ "docs": {
3181
+ "stability": "stable",
3182
+ "summary": "The State to go to after the semaphored job completes."
3183
+ },
3184
+ "immutable": true,
3185
+ "locationInModule": {
3186
+ "filename": "src/index.ts",
3187
+ "line": 27
3188
+ },
3189
+ "name": "nextState",
3190
+ "type": {
3191
+ "fqn": "aws-cdk-lib.aws_stepfunctions.State"
3192
+ }
3193
+ },
3194
+ {
3195
+ "abstract": true,
3196
+ "docs": {
3197
+ "remarks": "Significantly increases CloudFormation template size. Default: false.",
3198
+ "stability": "stable",
3199
+ "summary": "Add detailed comments to lock related states."
3200
+ },
3201
+ "immutable": true,
3202
+ "locationInModule": {
3203
+ "filename": "src/index.ts",
3204
+ "line": 35
3205
+ },
3206
+ "name": "comments",
3207
+ "optional": true,
3208
+ "type": {
3209
+ "primitive": "boolean"
3210
+ }
3211
+ },
3212
+ {
3213
+ "abstract": true,
3214
+ "docs": {
3215
+ "remarks": "Throws an error if a different `limit` is specified. Default: false.",
3216
+ "stability": "stable",
3217
+ "summary": "Explicility allow the reuse of a named lock from a previously generated job."
3218
+ },
3219
+ "immutable": true,
3220
+ "locationInModule": {
3221
+ "filename": "src/index.ts",
3222
+ "line": 31
3223
+ },
3224
+ "name": "reuseLock",
3225
+ "optional": true,
3226
+ "type": {
3227
+ "primitive": "boolean"
3228
+ }
3229
+ },
3172
3230
  {
3173
3231
  "abstract": true,
3174
3232
  "docs": {
3175
3233
  "default": "PAY_PER_REQUEST",
3234
+ "remarks": "Note: This property can only be set on the first instantiation of a `Semaphore` per stack",
3176
3235
  "stability": "stable",
3177
3236
  "summary": "Optionally set the DynamoDB table to have a specific read/write capacity with PROVISIONED billing."
3178
3237
  },
3179
3238
  "immutable": true,
3180
3239
  "locationInModule": {
3181
3240
  "filename": "src/index.ts",
3182
- "line": 15
3241
+ "line": 41
3183
3242
  },
3184
3243
  "name": "tableReadWriteCapacity",
3185
3244
  "optional": true,
@@ -3188,7 +3247,7 @@
3188
3247
  }
3189
3248
  }
3190
3249
  ],
3191
- "symbolId": "src/index:SemaphoreGeneratorProps"
3250
+ "symbolId": "src/index:SemaphoreProps"
3192
3251
  },
3193
3252
  "@dontirun/state-machine-semaphore.TableReadWriteCapacity": {
3194
3253
  "assembly": "@dontirun/state-machine-semaphore",
@@ -3201,7 +3260,7 @@
3201
3260
  "kind": "interface",
3202
3261
  "locationInModule": {
3203
3262
  "filename": "src/index.ts",
3204
- "line": 21
3263
+ "line": 47
3205
3264
  },
3206
3265
  "name": "TableReadWriteCapacity",
3207
3266
  "properties": [
@@ -3213,7 +3272,7 @@
3213
3272
  "immutable": true,
3214
3273
  "locationInModule": {
3215
3274
  "filename": "src/index.ts",
3216
- "line": 22
3275
+ "line": 48
3217
3276
  },
3218
3277
  "name": "readCapacity",
3219
3278
  "type": {
@@ -3228,7 +3287,7 @@
3228
3287
  "immutable": true,
3229
3288
  "locationInModule": {
3230
3289
  "filename": "src/index.ts",
3231
- "line": 23
3290
+ "line": 49
3232
3291
  },
3233
3292
  "name": "writeCapacity",
3234
3293
  "type": {
@@ -3239,6 +3298,6 @@
3239
3298
  "symbolId": "src/index:TableReadWriteCapacity"
3240
3299
  }
3241
3300
  },
3242
- "version": "0.0.1",
3243
- "fingerprint": "rtZDjzZsKq4BcpOi5+RDr3/GYKk2imgx9sRer+WXJ8s="
3301
+ "version": "0.1.2",
3302
+ "fingerprint": "p4nPFtVXcp81mfWyJDlagzlkE+ZU5HSugIVg4lM7fFQ="
3244
3303
  }