Skip to content

Commit

Permalink
Merge pull request #333 from OlivierAlbertini/feature/add-aws-step-fu…
Browse files Browse the repository at this point in the history
…nction-client

feat: add aws step function client
  • Loading branch information
OlivierAlbertini committed Feb 27, 2024
2 parents 0f0363b + 4d5b372 commit 521d358
Show file tree
Hide file tree
Showing 175 changed files with 4,726 additions and 2,867 deletions.
32 changes: 28 additions & 4 deletions examples/basic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,30 @@ $ # from this directory
$ npm install
```

### Configuring Step function

#### Deploying new workflow

##### Use CloudFormation and the AWS CDK (recommanded)

Todo: provide steps

##### Manually

In `examples/basic/bpmn/stepfunction/BPMN_DEMO.json`, you will need to specify the `QueueUrl` and in `examples/basic/src/deploy.ts` , you must specify the `roleArn` to use for deploying the new workflow.

Notice that you can skip this step if you deploy the workflow through the AWS Step function UI and it won't be necessary to run `npm run deploy`

### For All files

You must specify the following environment variables :

- AWS_REGION
- AWS_ACCESS_KEY_ID
- AWS_SECRET_ACCESS_KEY
- AWS_SQS_QUEUE_URL
- AWS_SQS_WAIT_TIME_SECONDS (Optional)

(Optional) Setup, we can switch to `TAG.camundaBpm` or `TAG.stepFunction` in order to use both plateform (some comments are added in the example).

```sh
Expand All @@ -22,12 +46,12 @@ $ npm run build

```sh
$ # from this directory
$ # deploy a bpmn provided in the example
$ npm camunda:deploy
$ # deploy the workflow provided in the example
$ npm run deploy
$ # create instance(s)
$ npm camunda:create-instance
$ npm run create-instance
$ # run worker
$ npm camunda:worker
$ npm run worker
```

## Useful links
Expand Down
37 changes: 37 additions & 0 deletions examples/basic/bpmn/stepfunction/BPMN_DEMO.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"Comment": "A description of my state machine",
"StartAt": "Activity",
"States": {
"Activity": {
"Type": "Task",
"Resource": "arn:aws:states:::sqs:sendMessage.waitForTaskToken",
"Parameters": {
"MessageBody": {
"body.$": "$",
"properties": {
"activityId": "sample_activity",
"retries.$": "$$.State.RetryCount",
"bpmnProcessId.$": "$$.StateMachine.Id",
"jobKey.$": "$$.Task.Token",
"workflowInstanceKey.$": "$$.Execution.Id"
}
},
"QueueUrl": "<YOUR QUEUE URL>"
},
"End": true,
"Retry": [
{
"ErrorEquals": [
"States.ALL"
],
"BackoffRate": 2,
"IntervalSeconds": 1,
"MaxAttempts": 5,
"Comment": "Basic Retrier"
}
],
"HeartbeatSeconds": 30,
"TimeoutSeconds": 200
}
}
}
24 changes: 12 additions & 12 deletions examples/basic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,31 @@
"lint": "eslint . --ext .ts && prettier -l \"src/**/*.ts\"",
"lint-fix": "prettier \"./**/*.ts\" --write && eslint . --ext .ts --fix",
"check-conflicts": "eslint --print-config tests/utils/func-test.ts | eslint-config-prettier-check",
"camunda:deploy": "node ./lib/src/deploy.js",
"camunda:create-instance": "node ./lib/src/create-process-instances.js",
"camunda:worker": "node ./lib/src/worker.js"
"deploy": "node ./lib/src/deploy.js",
"create-instance": "node ./lib/src/create-process-instances.js",
"worker": "node ./lib/src/worker.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/VilledeMontreal/workit.git"
},
"devDependencies": {
"@types/node": "^20.10.4",
"@typescript-eslint/eslint-plugin": "^6.14.0",
"@typescript-eslint/parser": "^6.14.0",
"eslint": "^8.55.0",
"@types/node": "^20.10.8",
"@typescript-eslint/eslint-plugin": "^6.18.1",
"@typescript-eslint/parser": "^6.18.1",
"eslint": "^8.56.0",
"eslint-config-airbnb-typescript": "^17.1.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-header": "^3.1.1",
"eslint-plugin-import": "^2.29.0",
"eslint-plugin-prettier": "^5.0.1",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-prettier": "^5.1.3",
"prettier": "^3.1.1",
"typescript": "^4.9.5"
},
"dependencies": {
"@villedemontreal/workit": "^6.0.0-dev",
"@villedemontreal/workit-core": "^6.0.0-dev",
"@villedemontreal/workit-types": "^6.0.0-dev",
"@villedemontreal/workit": "6.0.2-dev",
"@villedemontreal/workit-core": "6.0.2-dev",
"@villedemontreal/workit-types": "6.0.2-dev",
"axios": "^1.6.2"
},
"keywords": [
Expand Down
18 changes: 14 additions & 4 deletions examples/basic/src/create-process-instances.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,34 @@
/*
* Copyright (c) 2023 Ville de Montreal. All rights reserved.
* Copyright (c) 2024 Ville de Montreal. All rights reserved.
* Licensed under the MIT license.
* See LICENSE file in the project root for full license information.
*/

// you can pass value here or an another (safer) way
// process.env.AWS_REGION = 'us-east-1';
// process.env.AWS_ACCESS_KEY_ID = '<AWS_ACCESS_KEY_ID>';
// process.env.AWS_SECRET_ACCESS_KEY = '<AWS_SECRET_ACCESS_KEY>';
// process.env.AWS_SQS_WAIT_TIME_SECONDS = '20';

import { SERVICE_IDENTIFIER as CORE_IDENTIFIER, TAG } from '@villedemontreal/workit';
import { IoC } from '@villedemontreal/workit-core';
import { IWorkflowClient } from '@villedemontreal/workit-types';

(async (): Promise<void> => {
const cm = IoC.get<IWorkflowClient>(CORE_IDENTIFIER.client_manager, TAG.camundaBpm);
const platform = TAG.stepFunction;
const cm = IoC.get<IWorkflowClient>(CORE_IDENTIFIER.client_manager, platform);
for (let index = 0; index < 1; index += 1) {
await cm.createWorkflowInstance({
bpmnProcessId: 'BPMN_DEMO',
bpmnProcessId:
platform === TAG.camundaBpm
? 'BPMN_DEMO'
: `arn:aws:states:${process.env.AWS_REGION}:<YOUR-AWS-ACCOUNT-ID>:stateMachine:Basic-Exemple`,
variables: {
amount: 1000,
hello: 'world',
},
});
}

console.log('Success!');
console.info('Success!');
})();
49 changes: 39 additions & 10 deletions examples/basic/src/deploy.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,44 @@
/*
* Copyright (c) 2023 Ville de Montreal. All rights reserved.
* Copyright (c) 2024 Ville de Montreal. All rights reserved.
* Licensed under the MIT license.
* See LICENSE file in the project root for full license information.
*/

// you can pass value here or an another (safer) way
// process.env.AWS_REGION = 'us-east-1';
// process.env.AWS_SQS_QUEUE_URL = '<SQS_QUEUE_URL>'
// process.env.AWS_ACCESS_KEY_ID = '<AWS_ACCESS_KEY_ID>';
// process.env.AWS_SECRET_ACCESS_KEY = '<AWS_SECRET_ACCESS_KEY>';
// process.env.AWS_SQS_WAIT_TIME_SECONDS = '20';

import { SERVICE_IDENTIFIER as CORE_IDENTIFIER, TAG } from '@villedemontreal/workit';
import { IoC } from '@villedemontreal/workit-core';
import { IWorkflowClient } from '@villedemontreal/workit-types';

(async (): Promise<void> => {
const cm = IoC.get<IWorkflowClient>(CORE_IDENTIFIER.client_manager, TAG.camundaBpm);
const path = `${process.cwd()}/bpmn/BPMN_DEMO.bpmn`;
await cm.deployWorkflow(path);
console.log('Success!');
})();
import { IoC, Worker } from '@villedemontreal/workit-core';
import { HelloWorldTask } from '../tasks/helloWorldTask';

enum LOCAL_IDENTIFIER {
sampleActivity = 'Get credit limit',
}

IoC.bindTo(HelloWorldTask, LOCAL_IDENTIFIER.sampleActivity);
const worker = IoC.get<Worker>(CORE_IDENTIFIER.worker, TAG.stepFunction);

const stop = (): void => {
console.info('SIGTERM signal received.');
console.log('Closing worker');
worker
.stop()
.then(() => {
console.log('worker closed');
process.exit(0);
})
.catch((e: Error) => {
console.log(e);
process.exit(1);
});
};

worker.start();
worker.run();

process.on('SIGINT', stop);
process.on('SIGTERM', stop);
6 changes: 5 additions & 1 deletion examples/basic/src/worker.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
/*
* Copyright (c) 2023 Ville de Montreal. All rights reserved.
* Copyright (c) 2024 Ville de Montreal. All rights reserved.
* Licensed under the MIT license.
* See LICENSE file in the project root for full license information.
*/
// process.env.AWS_REGION = 'us-east-1';
// process.env.AWS_ACCESS_KEY_ID = '<AWS_ACCESS_KEY_ID>';
// process.env.AWS_SECRET_ACCESS_KEY = '<AWS_SECRET_ACCESS_KEY>';
// process.env.AWS_SQS_WAIT_TIME_SECONDS = '20';

import { SERVICE_IDENTIFIER as CORE_IDENTIFIER, TAG } from '@villedemontreal/workit';
import { IoC, Worker } from '@villedemontreal/workit-core';
Expand Down
5 changes: 3 additions & 2 deletions examples/basic/tasks/helloWorldTask.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Ville de Montreal. All rights reserved.
* Copyright (c) 2024 Ville de Montreal. All rights reserved.
* Licensed under the MIT license.
* See LICENSE file in the project root for full license information.
*/
Expand All @@ -13,7 +13,8 @@ export class HelloWorldTask extends TaskBase<IMessage> {
const { properties } = message;

console.log(`Executing task: ${properties.activityId}`);
console.log(`${properties.bpmnProcessId}::${properties.processInstanceId} Servus!`);
console.log(properties);
console.log(`${properties.bpmnProcessId}::${properties.workflowInstanceKey} Servus!`);

const response = await axios.get('https://jsonplaceholder.typicode.com/todos/1');

Expand Down
18 changes: 9 additions & 9 deletions examples/binding/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,22 @@
"url": "git+https://github.com/VilledeMontreal/workit.git"
},
"devDependencies": {
"@types/node": "^20.10.4",
"@typescript-eslint/eslint-plugin": "^6.14.0",
"@typescript-eslint/parser": "^6.14.0",
"eslint": "^8.55.0",
"@types/node": "^20.10.8",
"@typescript-eslint/eslint-plugin": "^6.18.1",
"@typescript-eslint/parser": "^6.18.1",
"eslint": "^8.56.0",
"eslint-config-airbnb-typescript": "^17.1.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-header": "^3.1.1",
"eslint-plugin-import": "^2.29.0",
"eslint-plugin-prettier": "^5.0.1",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-prettier": "^5.1.3",
"prettier": "^3.1.1",
"typescript": "^4.9.5"
},
"dependencies": {
"@villedemontreal/workit": "^6.0.0-dev",
"@villedemontreal/workit-core": "^6.0.0-dev",
"@villedemontreal/workit-types": "^6.0.0-dev",
"@villedemontreal/workit": "6.0.2-dev",
"@villedemontreal/workit-core": "6.0.2-dev",
"@villedemontreal/workit-types": "6.0.2-dev",
"axios": "^1.6.2"
},
"keywords": [
Expand Down
2 changes: 1 addition & 1 deletion examples/binding/src/create-process-instances.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Ville de Montreal. All rights reserved.
* Copyright (c) 2024 Ville de Montreal. All rights reserved.
* Licensed under the MIT license.
* See LICENSE file in the project root for full license information.
*/
Expand Down
2 changes: 1 addition & 1 deletion examples/binding/src/deploy.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Ville de Montreal. All rights reserved.
* Copyright (c) 2024 Ville de Montreal. All rights reserved.
* Licensed under the MIT license.
* See LICENSE file in the project root for full license information.
*/
Expand Down
2 changes: 1 addition & 1 deletion examples/binding/src/worker.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Ville de Montreal. All rights reserved.
* Copyright (c) 2024 Ville de Montreal. All rights reserved.
* Licensed under the MIT license.
* See LICENSE file in the project root for full license information.
*/
Expand Down
2 changes: 1 addition & 1 deletion examples/binding/tasks/helloWorldTask.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Ville de Montreal. All rights reserved.
* Copyright (c) 2024 Ville de Montreal. All rights reserved.
* Licensed under the MIT license.
* See LICENSE file in the project root for full license information.
*/
Expand Down
2 changes: 1 addition & 1 deletion examples/binding/tasks/helloWorldTaskV2.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Ville de Montreal. All rights reserved.
* Copyright (c) 2024 Ville de Montreal. All rights reserved.
* Licensed under the MIT license.
* See LICENSE file in the project root for full license information.
*/
Expand Down
2 changes: 1 addition & 1 deletion examples/binding/tasks/helloWorldTaskV3.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Ville de Montreal. All rights reserved.
* Copyright (c) 2024 Ville de Montreal. All rights reserved.
* Licensed under the MIT license.
* See LICENSE file in the project root for full license information.
*/
Expand Down
18 changes: 9 additions & 9 deletions examples/event/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,22 @@
"url": "git+https://github.com/VilledeMontreal/workit.git"
},
"devDependencies": {
"@types/node": "^20.10.4",
"@typescript-eslint/eslint-plugin": "^6.14.0",
"@typescript-eslint/parser": "^6.14.0",
"eslint": "^8.55.0",
"@types/node": "^20.10.8",
"@typescript-eslint/eslint-plugin": "^6.18.1",
"@typescript-eslint/parser": "^6.18.1",
"eslint": "^8.56.0",
"eslint-config-airbnb-typescript": "^17.1.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-header": "^3.1.1",
"eslint-plugin-import": "^2.29.0",
"eslint-plugin-prettier": "^5.0.1",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-prettier": "^5.1.3",
"prettier": "^3.1.1",
"typescript": "^4.9.5"
},
"dependencies": {
"@villedemontreal/workit": "^6.0.0-dev",
"@villedemontreal/workit-core": "^6.0.0-dev",
"@villedemontreal/workit-types": "^6.0.0-dev",
"@villedemontreal/workit": "6.0.2-dev",
"@villedemontreal/workit-core": "6.0.2-dev",
"@villedemontreal/workit-types": "6.0.2-dev",
"axios": "^1.6.2"
},
"keywords": [
Expand Down
2 changes: 1 addition & 1 deletion examples/event/src/create-process-instances.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Ville de Montreal. All rights reserved.
* Copyright (c) 2024 Ville de Montreal. All rights reserved.
* Licensed under the MIT license.
* See LICENSE file in the project root for full license information.
*/
Expand Down
2 changes: 1 addition & 1 deletion examples/event/src/deploy.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Ville de Montreal. All rights reserved.
* Copyright (c) 2024 Ville de Montreal. All rights reserved.
* Licensed under the MIT license.
* See LICENSE file in the project root for full license information.
*/
Expand Down
2 changes: 1 addition & 1 deletion examples/event/src/worker.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Ville de Montreal. All rights reserved.
* Copyright (c) 2024 Ville de Montreal. All rights reserved.
* Licensed under the MIT license.
* See LICENSE file in the project root for full license information.
*/
Expand Down
2 changes: 1 addition & 1 deletion examples/event/tasks/helloWorldTask.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Ville de Montreal. All rights reserved.
* Copyright (c) 2024 Ville de Montreal. All rights reserved.
* Licensed under the MIT license.
* See LICENSE file in the project root for full license information.
*/
Expand Down
Loading

0 comments on commit 521d358

Please sign in to comment.