0.1.0-beta14 • Published 18 days ago

simple-workflows v0.1.0-beta14

Weekly downloads
-
License
MIT
Repository
github
Last release
18 days ago

simple-workflows

Simple repeatable workflows and activities as code.

Goals:

  • Repeatable long running programs.
  • Close to zero dependencies.
  • No extra infrastructure requirements.
  • Statically typed.

History/state can be serialized to:

  • Memory
  • File System
  • Azure Table and Blob Storage

Inspired by Azure Durable Function and Temporal.

Activities

All activities is just normal functions that return promises, but must be idempotent and both args and return value must be serializable.

Example activity:

export async function greet(name: string): Promise<string> {
    return `Hello, ${name}!`;
}

Workflows

Workflows is build by activities. When activities is used in workflows, they must be passed to the proxyActivities function:

import * as activities from '../activities';
import { proxyActivities } from "simple-workflows";

const { greet } = proxyActivities(activities, {});

export async function greetWorkflow(name: string): Promise<string> {
    return await greet(name);
}

Getting started

import { WorkflowWorker } from "simple-workflows";

const worker = WorkflowWorker.getInstance();

const handle = await worker.start(greetWorkflow, {
    args: ["debug"],
    workflowId: "debug",
});

console.log(`Started workflow ${handle.workflowId}`);

let result = await handle.result();

Custom serialization

By default standard JSON serialization is used, the serialization can be customized by setting serializer on the store eg.:

import superjson from 'superjson';

const worker = WorkflowWorker.getInstance();
const store = new DurableFunctionsWorkflowHistoryStore({
  connectionString: "UseDevelopmentStorage=true",
  serializer: superjson,
});
worker.store = store;

Limitations

  • Workflows & activities is executed in the current process
  • Workflows & activities will not forcefully be stopped on timeout
0.1.0-beta14

18 days ago

0.1.0-beta13

5 months ago

0.1.0-beta12

6 months ago

0.1.0-beta11

6 months ago

0.1.0-beta10

6 months ago

0.1.0-beta9

7 months ago

0.1.0-beta8

10 months ago

0.1.0-beta7

1 year ago

0.1.0-beta6

1 year ago

0.1.0-beta5

1 year ago

0.1.0-beta4

1 year ago

0.1.0-beta3

2 years ago

0.1.0-beta2

2 years ago

0.1.0-beta1

2 years ago

0.1.0-beta0

2 years ago