Documentation
¶
Overview ¶
Package dwarf is a standalone, embeddable workflow-orchestration engine.
Dwarf executes workflow graphs: it dispatches tasks, manages state between steps, and handles fan-out/fan-in, retries, sleeps, conditional routing, subgraphs, and human-in-the-loop interrupts. It is library code with no built-in transport: a host application wires it to its own task execution, graph storage, and observability through a small set of injected dependency interfaces (see the engine package). It depends only on a SQL database (via sequel).
This root package is a thin convenience: NewEngine returns an *engine.Engine. The real API lives in two sub-packages:
- github.com/microbus-io/dwarf/engine - the engine: Startup/Shutdown, the Create/Run/Await operations, configuration, and the dependency interfaces. Import this only in the process that hosts the engine.
- github.com/microbus-io/dwarf/workflow - the pure types: Graph, Flow, FlowOptions, FlowOutcome, and reducers. Import this in code that defines tasks and graphs; it has no heavy dependencies.
A 30-second taste, using the in-process test harness:
proxy := engine.NewTestProxy()
g := workflow.NewGraph("Greet")
g.SetEndpoint("Hello", "http://example/hello") // node "Hello" dispatches to this endpoint URL
g.AddTransition("Hello", workflow.END)
proxy.HandleGraph("http://example/greet", g)
proxy.HandleTask("http://example/hello", func(ctx context.Context, f *workflow.Flow) error {
f.SetString("greeting", "hello "+f.GetString("name"))
return nil
})
eng := dwarf.NewEngineUnderTest(t.Name()) // SQLite in-memory, auto-dropped at test end
defer eng.Shutdown(ctx)
eng.SetHost(proxy)
eng.Startup(ctx)
_, out, _ := eng.Run(ctx, "http://example/greet", map[string]any{"name": "ada"}, nil)
fmt.Println(out.State["greeting"]) // hello ada
See the docs/ directory in the repository for guides on graphs, tasks, scheduling, observability, and deployment.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewEngineUnderTest ¶ added in v0.10.0
NewEngineUnderTest creates a workflow engine wired for testing: isolated, auto-dropped databases keyed by the given test name. The caller owns teardown (defer eng.Shutdown(ctx)). See engine.NewEngineUnderTest.
Types ¶
This section is empty.
Directories
¶
| Path | Synopsis |
|---|---|
|
The bench command drives the dwarf engine through its public API against a real database and measures step/flow/MB throughput and latency at a sweep of closed-loop concurrencies.
|
The bench command drives the dwarf engine through its public API against a real database and measures step/flow/MB throughput and latency at a sweep of closed-loop concurrencies. |
|
Package engine is the dwarf workflow-orchestration engine.
|
Package engine is the dwarf workflow-orchestration engine. |
|
internal
|
|
|
candidates
Package candidates holds the per-replica bounded set of step candidates produced by the engine's refillers.
|
Package candidates holds the per-replica bounded set of step candidates produced by the engine's refillers. |
|
claimstracker
Package claimstracker records which steps a replica has a claim CAS in flight on, so a sibling worker that pops the same candidate can skip it instead of paying a round trip to lose the CAS.
|
Package claimstracker records which steps a replica has a claim CAS in flight on, so a sibling worker that pops the same candidate can skip it instead of paying a round trip to lose the CAS. |
|
database
Package database owns the engine's sharded SQL connections: it opens and migrates every shard, routes by 1-based shard index, fans an operation out over all shards, and closes them.
|
Package database owns the engine's sharded SQL connections: it opens and migrates every shard, routes by 1-based shard index, fans an operation out over all shards, and closes them. |
|
enginetest
Package enginetest holds the engine test helpers that are shared across package boundaries - by the white-box tests that stay in package engine AND by the black-box tests in the fixtures package.
|
Package enginetest holds the engine test helpers that are shared across package boundaries - by the white-box tests that stay in package engine AND by the black-box tests in the fixtures package. |
|
faninmap
Package faninmap derives the fan-out -> fan-in convergence map of a workflow graph: which node a given fan-out source's branches converge on.
|
Package faninmap derives the fan-out -> fan-in convergence map of a workflow graph: which node a given fan-out source's branches converge on. |
|
keys
Package keys encodes and decodes the engine's composite flow and step keys.
|
Package keys encodes and decodes the engine's composite flow and step keys. |
|
latch
Package latch parks callers on a key until something reports that key done.
|
Package latch parks callers on a key until something reports that key done. |
|
lru
Package lru provides a small thread-safe LRU cache with a per-entry TTL.
|
Package lru provides a small thread-safe LRU cache with a per-entry TTL. |
|
peers
Package peers reports the fleet sharing one shard's database, from that shard's replica registry.
|
Package peers reports the fleet sharing one shard's database, from that shard's replica registry. |
|
pipeline
Package pipeline runs one shard's supply cycle: it looks at what is due, asks the planner what it may serve, fetches that, and pushes it to the candidate cache the workers drain.
|
Package pipeline runs one shard's supply cycle: it looks at what is due, asks the planner what it may serve, fetches that, and pushes it to the candidate cache the workers drain. |
|
piston
Package piston supplies step candidates from one shard.
|
Package piston supplies step candidates from one shard. |
|
planner
Package planner decides which work a shard may dispatch, given what every shard last reported.
|
Package planner decides which work a shard may dispatch, given what every shard last reported. |
|
staterefs
Package staterefs stores a large carried state field once instead of copying it into every step that merely passes it along.
|
Package staterefs stores a large carried state field once instead of copying it into every step that merely passes it along. |
|
turnstile
Package turnstile bounds how many callers may hold a resource at once AND decides which waiter is admitted next: the lowest priority band, and within a band the job that started earliest.
|
Package turnstile bounds how many callers may hold a resource at once AND decides which waiter is admitted next: the lowest priority band, and within a band the job that started earliest. |
|
workers
Package workers holds the demand side of dispatch: a CREW of goroutines that pop step candidates from the cache and hand each to one callback.
|
Package workers holds the demand side of dispatch: a CREW of goroutines that pop step candidates from the cache and hand each to one callback. |
|
Package workflow holds the pure data types of the dwarf workflow engine: the building blocks a host uses to define workflows and the carriers it reads and writes when running tasks.
|
Package workflow holds the pure data types of the dwarf workflow engine: the building blocks a host uses to define workflows and the carriers it reads and writes when running tasks. |