Skip to content

Commit

Permalink
docs: update readme for stepfunctions
Browse files Browse the repository at this point in the history
also adjust mappings and exceptions

Signed-off-by: Olivier Albertini <[email protected]>
  • Loading branch information
OlivierAlbertini committed Apr 25, 2024
1 parent 0729ffe commit 8621fec
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 23 deletions.
Binary file added .repo/sfn_demo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 6 additions & 17 deletions getting-started/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,29 +39,18 @@ You should see in the console, all activities crushed by the worker. Now, if you

## AWS Step function

If you don't access to AWS Step function, you can use docker command to run it in the root folder:
How to setup step functions and the state machine : [link](./STEP_FUNCTIONS_SETUP.md) TODO

```bash
docker/run
```
Now, You should have a `Basic-Example` process definition visible here: TODO

TODO:

Now you just need to change the tag `TAG.camundaBpm` to `TAG.stepFunction`.
<p align="center">
<a href="../.repo/sfn_demo.png"><img src="../.repo/sfn_demo.png"></a>
</p>

After cloning the repo, open a terminal and go to `examples/basic`

Edit the file at `examples/basic/src/deploy.ts`, change the tag to `TAG.stepFunction` and *MUST* use a different bpmn file (one compatible with AWS Step function as content is different) `${ process.cwd() }/bpmn/stepfunction/BPMN_DEMO.bpmn` (the stepfunction folder contains `BPMN_DEMO.json`)

```bash
npm run build && npm run deploy
```
Now, You should have a `Demo` process definition visible here: http://localhost:8080/#/instances?filter=%7B%22active%22%3Atrue%2C%22incidents%22%3Atrue%2C%22workflow%22%3A%22BPMN_DEMO%22%2C%22version%22%3A%221%22%7D

TODO:
<p align="center">
<a href="./operate/zeebe-operate.png"><img src="./operate/zeebe-operate.png"></a>
</p>
Now you just need to change the tag `TAG.camundaBpm` to `TAG.stepFunction` and fill environment variables in code.

Edit the file at `examples/basic/src/create-process-instances.ts`, change the tag to `TAG.stepFunction`

Expand Down
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT license.
* See LICENSE file in the project root for full license information.
*/
import { IMessage, IStepFunctionClientConfig } from '@villedemontreal/workit-types';
import { IMessage, IStepFunctionClientConfig, IncidentException } from '@villedemontreal/workit-types';
import { StepFunctionClient } from '../sfnClient';
import * as fs from 'fs/promises';

Expand Down Expand Up @@ -54,16 +54,22 @@ export class StepFunctionRepository {
}

public sendTaskSuccess(message: IMessage): Promise<SendTaskSuccessCommandOutput> {
const params = { output: message.body ? JSON.stringify(message.body) : '{}', taskToken: message.properties.jobKey };
const payload = JSON.stringify(message.body);

if (payload.length > 262144) {
throw new IncidentException("payload (message.body) can't exceed 256KB");
}

const params = { output: message.body ? payload : '{}', taskToken: message.properties.jobKey };
const command = new SendTaskSuccessCommand(params);
return this._client.send(command);
}

public sendTaskFailure(error: Error, message: IMessage): Promise<SendTaskFailureCommandOutput> {
public sendTaskFailure(error: NodeJS.ErrnoException, message: IMessage): Promise<SendTaskFailureCommandOutput> {
const params = {
output: stringify(message.body),
cause: stringify(error).substring(0, 32768),
taskToken: message.properties.jobKey,
error: stringify(error),
error: (error.code || error.name || 'UnhandledException').substring(0, 256),
};
const command = new SendTaskFailureCommand(params);
return this._client.send(command);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class SfnSqsMapperProperties {
activityId: properties.activityId,
businessKey: properties.businessKey,
processInstanceId: task.ReceiptHandle,
workflowDefinitionVersion: Number(task.processDefinitionId.split(':')[1]),
workflowDefinitionVersion: properties.version === undefined ? 0 : Number(properties.version) || 0,
workflowInstanceKey: properties.workflowInstanceKey,
workflowKey: properties.workflowKey,
bpmnProcessId: properties.workflowKey,
Expand Down
4 changes: 4 additions & 0 deletions packages/workit-types/src/core/camunda/incidentException.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
*/

export class IncidentException extends Error {
public get code() {
return 'Workit.Incident';
}

public get retries() {
return 0;
}
Expand Down

0 comments on commit 8621fec

Please sign in to comment.