Skip to content

Commit

Permalink
Merge pull request #334 from OlivierAlbertini/feature/doc-step-functions
Browse files Browse the repository at this point in the history
docs: update readme for stepfunctions
  • Loading branch information
OlivierAlbertini authored Feb 29, 2024
2 parents 07a71d6 + eaf14e3 commit 0729ffe
Show file tree
Hide file tree
Showing 42 changed files with 346 additions and 712 deletions.
71 changes: 5 additions & 66 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,39 +39,13 @@ This package can be useful because:
| Package | Description |
| ---------------------------------------- | -----------------|
| [workit-bpm-client](https://github.com/VilledeMontreal/workit/tree/master/packages/workit-bpm-client) | This module provides a full control over the Camunda Bpm platform.<br> It use [`camunda-external-task-client-js`](https://github.com/camunda/camunda-external-task-client-js) by default. |
| [workit-stepfunction-client](https://github.com/VilledeMontreal/workit/tree/master/packages/workit-stepfunction-client) | This module provides a full control over the Step functions platform.<br> It use `@aws-sdk/client-sqs`, `@aws-sdk/client-sfn` by default. |

## Installing

```bash
npm i @villedemontreal/workit
```
or using the generator below
### Yo!

<p align="center"><img src=".repo/render1561149492572.gif?raw=true"/></p>

This generator will help you during your development with this library. It provides handy tools.

```bash
npm i -g @villedemontreal/workit-cli
```

#### Install a fresh new project

```bash
workit init
```
#### Generate tasks from your existing BPMN

```bash
workit create task --file /your/path.bpmn
```

#### Generate new task

```bash
workit create task
```

## How to use

Expand Down Expand Up @@ -108,28 +82,6 @@ const manager = IoC.get<IWorkflowClient>(CORE_IDENTIFIER.client_manager, TAG.cam
await manager.getWorkflow({ bpmnProcessId: "DEMO" });
```

### Update variables

```javascript
const manager = IoC.get<IWorkflowClient>(CORE_IDENTIFIER.client_manager, TAG.camundaBpm);
await manager.updateVariables({
processInstanceId: "5c50c48e-4691-11e9-8b8f-0242ac110002",
variables: { amount: 1000 }
});
```

### Publish message

```javascript
const manager = IoC.get<IWorkflowClient>(CORE_IDENTIFIER.client_manager, TAG.camundaBpm);
await manager.publishMessage({
correlation: {},
name: "catching",
variables: { amount: 100 },
messageId: "5c50c48e-4691-11e9-8b8f-0242ac110002"
});
```

### Create workflow instance

```javascript
Expand All @@ -142,20 +94,6 @@ await manager.createWorkflowInstance({
});
```

### Cancel workflow instance

```javascript
const manager = IoC.get<IWorkflowClient>(CORE_IDENTIFIER.client_manager, TAG.camundaBpm);
await manager.cancelWorkflowInstance("4651614f-4b3c-11e9-b5b3-ee5801424400");
```

### Resolve incident

```javascript
const manager = IoC.get<IWorkflowClient>(CORE_IDENTIFIER.client_manager, TAG.camundaBpm);
await manager.resolveIncident("c84fce6c-518e-11e9-bd78-0242ac110003");
```

### Define tasks (your bpmn activities)

You can define many tasks to one worker. It will handle all messages and will route to the right tasks.
Expand All @@ -172,7 +110,6 @@ export class HelloWorldTask extends TaskBase<IMessage> {
}
}


enum LOCAL_IDENTIFIER {
// sample_activity must match the activityId in your bpmn
sample_activity= 'sample_activity'
Expand Down Expand Up @@ -351,7 +288,9 @@ npm test
## Built With

* [camunda-external-task-client-js](https://github.com/camunda/camunda-external-task-client-js) - nodejs client for Camunda BPM
* [inversify](https://github.com/inversify/InversifyJS) - Dependency injection
* [@aws-sdk/client-sqs](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/sqs/) - nodejs client for receiving messages from the queue
* [@aws-sdk/client-sfn](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/sfn/) - nodejs client for managing state machines and acknowledging process
* [inversify](https://github.com/inversify/InversifyJS) - dependency injection
* [opentelemetry](https://opentelemetry.io/) - add instrumentation to the operations (provides a single set of APIs, libraries to capture distributed traces)

## Philosophy
Expand Down Expand Up @@ -386,7 +325,7 @@ We use [SemVer](http://semver.org/) for versioning. For the versions available,

workit | AWS Step function | Camunda BPM
-- | -- | --
\>=6.0.0 | TODO | 7.6 to latest
\>=6.0.0 | all | 7.6 to latest

## Maintainers

Expand Down
44 changes: 5 additions & 39 deletions README_FR.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Ce framework offre les avantages suivants:
| Librairie | Description |
| ----------------------- | -----------------|
| [workit-bpm-client](https://github.com/VilledeMontreal/workit/tree/master/packages/workit-bpm-client) | Ce module fournit un contrôle complet pour intéragir avec la plateforme Camunda Bpm.<br> Il utilise [`camunda-external-task-client-js`](https://github.com/camunda/camunda-external-task-client-js) par défaut. |

| [workit-stepfunction-client](https://github.com/VilledeMontreal/workit/tree/master/packages/workit-stepfunction-client) | Ce module fournit un contrôle complet pour intéragir avec la plateforme Step functions.<br> Par défaut, il utilise `@aws-sdk/client-sqs`, `@aws-sdk/client-sfn`. |
## L'installation

```bash
Expand Down Expand Up @@ -82,28 +82,6 @@ const manager = IoC.get<IWorkflowClient>(CORE_IDENTIFIER.client_manager, TAG.cam
await manager.getWorkflow({ bpmnProcessId: "DEMO" });
```

### Mettre à jour les variables

```javascript
const manager = IoC.get<IWorkflowClient>(CORE_IDENTIFIER.client_manager, TAG.camundaBpm);
await manager.updateVariables({
processInstanceId: "5c50c48e-4691-11e9-8b8f-0242ac110002",
variables: { amount: 1000 }
});
```

### Publier un message

```javascript
const manager = IoC.get<IWorkflowClient>(CORE_IDENTIFIER.client_manager, TAG.camundaBpm);
await manager.publishMessage({
correlation: {},
name: "catching",
variables: { amount: 100 },
messageId: "5c50c48e-4691-11e9-8b8f-0242ac110002"
});
```

### Créer une instance de flux de travail

```javascript
Expand All @@ -116,20 +94,6 @@ await manager.createWorkflowInstance({
});
```

### Annuler l'instance d'un flux de travail

```javascript
const manager = IoC.get<IWorkflowClient>(CORE_IDENTIFIER.client_manager, TAG.camundaBpm);
await manager.cancelWorkflowInstance("4651614f-4b3c-11e9-b5b3-ee5801424400");
```

### Résoudre l'incident

```javascript
const manager = IoC.get<IWorkflowClient>(CORE_IDENTIFIER.client_manager, TAG.camundaBpm);
await manager.resolveIncident("c84fce6c-518e-11e9-bd78-0242ac110003");
```

### Définir les tâches (vos activités bpmn)

Vous pouvez définir plusieurs tâches pour un seul Worker. Il traitera tous les messages et acheminera les requêtes vers les bonnes tâches.
Expand Down Expand Up @@ -323,7 +287,9 @@ npm test
## Construit avec

* [camunda-external-task-client-js](https://github.com/camunda/camunda-external-task-client-js) - client nodejs pour Camunda BPM
* [inversify](https://github.com/inversify/InversifyJS) - injection de dépendence
* [@aws-sdk/client-sqs](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/sqs/) - client nodejs pour recevoir les messages de la file d'attente
* [@aws-sdk/client-sfn](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/sfn/) - client nodejs pour gérer l'état des processus
* [inversify](https://github.com/inversify/InversifyJS) - injection de dépendance
* [opentelemetry](https://opentelemetry.io/) - ajouter de l'instrumentation aux opérations

## Philosophie
Expand All @@ -348,7 +314,7 @@ Nous utilisons [SemVer](http://semver.org/) pour la gestion des versions. Pour l

workit | AWS Step function | Camunda BPM
-- | -- | --
\>=6.0.0 | TODO | 7.6 to latest
\>=6.0.0 | tous | 7.6 to latest


## Mainteneurs
Expand Down
6 changes: 3 additions & 3 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ $ npm install
$ # inside a directory

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

## Useful links
Expand Down
4 changes: 2 additions & 2 deletions examples/basic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ 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.
In `examples/basic/workflow/stepfunction/WORKFLOW_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`

Expand All @@ -35,7 +35,7 @@ You must specify the following environment variables :
- 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).
(Optional) Setup, we can switch to `TAG.camundaBpm` or `TAG.stepFunction` in order to use both platforms (some comments are added in the example).

```sh
$ # from this directory
Expand Down
2 changes: 1 addition & 1 deletion examples/basic/src/create-process-instances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { IWorkflowClient } from '@villedemontreal/workit-types';
bpmnProcessId:
platform === TAG.camundaBpm
? 'BPMN_DEMO'
: `arn:aws:states:${process.env.AWS_REGION}:<YOUR-AWS-ACCOUNT-ID>:stateMachine:Basic-Exemple`,
: `arn:aws:states:${process.env.AWS_REGION}:<YOUR-AWS-ACCOUNT-ID>:stateMachine:Basic-Example`,
variables: {
amount: 1000,
hello: 'world',
Expand Down
51 changes: 21 additions & 30 deletions examples/basic/src/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,30 @@

// 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, Worker } from '@villedemontreal/workit-core';
import { HelloWorldTask } from '../tasks/helloWorldTask';
import { IoC } from '@villedemontreal/workit-core';
import { IWorkflowClient } from '@villedemontreal/workit-types';

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);
(async (): Promise<void> => {
const platform = TAG.camundaBpm;
const cm = IoC.get<IWorkflowClient>(CORE_IDENTIFIER.client_manager, platform);
const path =
platform === TAG.camundaBpm
? `${process.cwd()}/workflow/camunda/BPMN_DEMO.bpmn`
: `${process.cwd()}/workflow/stepfunction/WORKFLOW_DEMO.json`;
const result =
platform === TAG.camundaBpm
? await cm.deployWorkflow(path)
: await cm.deployWorkflow(path, {
name: 'Basic-Example',
roleArn: 'arn:aws:iam::<YOUR-AWS-ACCOUNT-ID>:role/service-role/<YOUR ROLE>',
});
console.info('Success!');
console.warn(
`Please, provide the following value "${result.workflows[0].bpmnProcessId}" to bpmnProcessId variable in create-process-instances.ts file for creating an instance`,
);
})();
File renamed without changes.
6 changes: 3 additions & 3 deletions examples/binding/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ $ npm run build
```sh
$ # from this directory
$ # deploy a bpmn provided in the example
$ npm camunda:deploy
$ npm deploy
$ # create instance(s)
$ npm camunda:create-instance
$ npm create-instance
$ # run worker
$ npm camunda:worker
$ npm worker
```

## Useful links
Expand Down
6 changes: 3 additions & 3 deletions examples/binding/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
"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",
Expand Down
2 changes: 1 addition & 1 deletion examples/binding/src/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ 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_P_DEMO.bpmn`;
const path = `${process.cwd()}/workflow/camunda/BPMN_P_DEMO.bpmn`;
await cm.deployWorkflow(path);
console.log('Success!');
})();
File renamed without changes.
Loading

0 comments on commit 0729ffe

Please sign in to comment.