Skip to content

Commit 3bd7700

Browse files
committed
Describe backends
1 parent df5eb6c commit 3bd7700

File tree

1 file changed

+83
-10
lines changed

1 file changed

+83
-10
lines changed

docs/source/includes/_backends.md

Lines changed: 83 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,100 @@
11
# Backends
22

3-
There are three backend implementations maintained in this repository.
3+
There are three backend implementations maintained in this repository. Some backend implementations have custom options and all of them accept:
4+
5+
- `WithStickyTimeout(timeout time.Duration)` - Set the timeout for sticky tasks. Defaults to 30 seconds
6+
- `WithLogger(logger *slog.Logger)` - Set the logger implementation
7+
- `WithMetrics(client metrics.Client)` - Set the metrics client
8+
- `WithTracerProvider(tp trace.TracerProvider)` - Set the OpenTelemetry tracer provider
9+
- `WithConverter(converter converter.Converter)` - Provide a custom `Converter` implementation
10+
- `WithContextPropagator(prop workflow.ContextPropagator)` - Adds a custom context propagator
11+
412

513
## SQLite
614

15+
```go
16+
func NewSqliteBackend(path string, opts ...option)
17+
```
18+
19+
Create a new SQLite backend instance with `NewSqliteBackend`.
20+
21+
### Options
22+
23+
- `WithApplyMigrations(applyMigrations bool)` - Set whether migrations should be applied on startup. Defaults to `true`
24+
- `WithBackendOptions(opts ...backend.BackendOption)` - Apply generic backend options
25+
26+
### Schema
27+
28+
See `migrations/sqlite` for the schema and migrations. Main tables:
29+
30+
- `instances` - Tracks workflow instances. Functions as instance queue joined with `pending_events`
31+
- `pending_events` - Pending events for workflow instances
32+
- `history` - History for workflow instances
33+
- `activities` - Queue of pending activities
34+
- `attributes` - Payloads of events
35+
736
## MySQL
837

38+
```go
39+
func NewMysqlBackend(host string, port int, user, password, database string, opts ...option)
40+
```
41+
42+
Create a new MySQL backend instance with `NewMysqlBackend`.
43+
44+
### Options
45+
46+
- `WithMySQLOptions(f func(db *sql.DB))` - Apply custom options to the MySQL database connection
47+
- `WithApplyMigrations(applyMigrations bool)` - Set whether migrations should be applied on startup. Defaults to `true`
48+
- `WithBackendOptions(opts ...backend.BackendOption)` - Apply generic backend options
49+
50+
51+
### Schema
52+
53+
See `migrations/mysql` for the schema and migrations. Main tables:
54+
55+
- `instances` - Tracks workflow instances. Functions as instance queue joined with `pending_events`
56+
- `pending_events` - Pending events for workflow instances
57+
- `history` - History for workflow instances
58+
- `activities` - Queue of pending activities
59+
- `attributes` - Payloads of events
60+
961
## Redis
1062

11-
### How it works
63+
```go
64+
func NewRedisBackend(client redis.UniversalClient, opts ...RedisBackendOption)
65+
```
66+
67+
Create a new Redis backend instance with `NewRedisBackend`.
68+
69+
### Options
70+
71+
- `WithBlockTimeout(timeout time.Duration)` - Set the timeout for blocking operations. Defaults to `5s`
72+
- `WithAutoExpiration(expireFinishedRunsAfter time.Duration)` - Set the expiration time for finished runs. Defaults to `0`, which never expires runs
73+
- `WithAutoExpirationContinueAsNew(expireContinuedAsNewRunsAfter time.Duration)` - Set the expiration time for continued as new runs. Defaults to `0`, which uses the same value as `WithAutoExpiration`
74+
- `WithBackendOptions(opts ...backend.BackendOption)` - Apply generic backend options
75+
76+
77+
### Schema/Keys
78+
79+
Shared keys:
80+
81+
- `instances-by-creation` - `ZSET` - Instances sorted by creation time
82+
- `instances-active` - `SET` - Active instances
83+
- `instances-expiring` - `SET` - Instances about to expire
1284

13-
#### Keys used
85+
- `task-queue:workflows` - `STREAM` - Task queue for workflows
86+
- `task-queue:activities` - `STREAM` - Task queue for activities
1487

15-
Global state:
88+
Instance specific keys:
1689

17-
- Future events TODO
18-
- Active instances
19-
- Expired instances
90+
- `active-instance-execution:{instanceID}` - Latest execution for a workflow instance
91+
- `instance:{instanceID}:{executionID}` - State of the workflow instance
92+
- `pending-events:{instanceID}:{executionID}` - `STREAM` - Pending events for a workflow instance
93+
- `history:{instanceID}:{executionID}` - `STREAM` - History for a workflow instance
94+
- `payload:{instanceID}:{executionID}` - `HASH` - Payloads of events for given workflow instance
2095
21-
State per instance:
96+
- `future-events` - `ZSET` - Events not yet visible like timer events
2297
23-
- History (`STREAM`)
24-
- Pending Events (`STREAM`)
2598
2699
27100
## Custom implementation

0 commit comments

Comments
 (0)