@usehelical/workflows 0.0.1-alpha.17 → 0.0.1-alpha.18
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/README.md +74 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,12 +1,80 @@
|
|
|
1
1
|
# Helical Workflows
|
|
2
2
|
|
|
3
|
-
Simple, typesafe durable workflows without bundler magic
|
|
4
|
-
|
|
5
3
|
> [!WARNING]
|
|
6
4
|
> This is a work in progress
|
|
7
5
|
|
|
8
|
-
|
|
6
|
+
Simple, typesafe durable workflows without bundler magic
|
|
7
|
+
|
|
8
|
+
## Features
|
|
9
|
+
|
|
10
|
+
- Effortless setup
|
|
11
|
+
- Effortless deployment
|
|
12
|
+
- Automatic workflow recovery
|
|
13
|
+
- Messages
|
|
14
|
+
- State
|
|
15
|
+
- Queues
|
|
16
|
+
|
|
17
|
+
# Getting started
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
Install the hkit CLI and apply migrations to your Postgres database
|
|
22
|
+
|
|
23
|
+
```sh
|
|
24
|
+
curl -sSfL https://releases.usehelical.com/install.sh | sh
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Apply migrations to your Postgres instance
|
|
28
|
+
|
|
29
|
+
```sh
|
|
30
|
+
hkit migrate --databaseUrl postgresql://postgres:postgres@localhost:5432/postgres
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Install the @usehelical/workflows npm package to use it in your project
|
|
34
|
+
|
|
35
|
+
```sh
|
|
36
|
+
pnpm add @usehelical/workflows
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Defining a workflow
|
|
40
|
+
|
|
41
|
+
Define a workflow by using the defineWorkflow function and execute steps by using the runStep function. It is important that the steps you run are idempotent to ensure correct and reliable execution of your workflow.
|
|
42
|
+
|
|
43
|
+
```ts
|
|
44
|
+
import { defineWorkflow, runStep } from '@usehelical/workflows/api';
|
|
45
|
+
|
|
46
|
+
export const checkoutWorkflow = defineWorkflow('checkout', async (id: string) => {
|
|
47
|
+
await runStep(async () => {
|
|
48
|
+
await decrementInventory();
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
await runStep(async () => {
|
|
52
|
+
await createOrder(id);
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Creating a worker
|
|
58
|
+
|
|
59
|
+
Create a worker by using the createWorker function registering the workflows it can run. And connecting it to the previously setup Postgres database.
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
import { createWorker } from '@usehelical/workflows';
|
|
63
|
+
|
|
64
|
+
export const worker = createWorker({
|
|
65
|
+
workflows: [checkoutWorkflow],
|
|
66
|
+
options: {
|
|
67
|
+
connectionString: process.env.DATABASE_URL,
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Starting a worker
|
|
73
|
+
|
|
74
|
+
Pass the workflow to the runWorkflow function and pass the arguments to the workflow as an array. The waitForResult function will await the workflow completion.
|
|
75
|
+
|
|
76
|
+
```ts
|
|
77
|
+
const { id, getStatus, waitForResult } = await worker.runWorkflow(checkoutWorkflow, [id]);
|
|
9
78
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
- low latency (making it suitable for user-facing ai workflows)
|
|
79
|
+
const { success, data, error } = await waitForResult();
|
|
80
|
+
```
|