Workflows and Test Suites
The Python workflow engine provides dependency ordering, async execution, timeouts, retry policies, cancellation, state changes, events, checkpointing, and results. It orchestrates Python step objects, but not every advertised workflow operation is implemented in the SDK.
Build a workflow
import asyncio
from storq import WorkflowBuilder
workflow = (
WorkflowBuilder("inspect database")
.inspect_format("sample.sqlite", name="format")
.build()
)
result = asyncio.run(workflow.execute())
print(result.status)
print(result.steps)
WorkflowBuilder.add_step(step, name=None, depends_on=None) adds a custom
WorkflowStep. Dependencies must refer to already-added step names when using
the builder. Workflow.add(step, depends_on=None) adds a step directly;
Workflow.validate() checks unique names, dependency references/cycles, config,
and retry policies.
Builder methods
| Method | Configuration | Current status |
|---|---|---|
inspect_format(database_path, name=None, depends_on=None) | SQLite/Storq format path | The native inspect_format call is bound. |
inspect_database(database_path=None, ...) | Adapter in workflow context | Returns the configured adapter object; it does not independently inspect a file. |
analyze_pages(database_path, ...) | Database path | Unsupported Python workflow step; raises NotImplementedError. |
analyze_wal(database_path, ...) | WAL path | Unsupported Python workflow step; raises NotImplementedError. |
create_snapshot(database_path=None, ...) | Source path | Unsupported native workflow step. |
inject_fault(fault_type=None, seed=None, ...) | Fault hint and seed | Unsupported native workflow step. Builder marks it non-idempotent. |
simulate_crash(trigger=None, value=None, ...) | Trigger hint | Unsupported native workflow step. Builder marks it non-idempotent. |
verify_recovery(...) | No arguments currently used | Unsupported native workflow step. |
investigate(...) | No arguments currently used | Unsupported native workflow step. |
execute_workload(workload=None, ...) | WorkloadConfig property values | Generates transactions using the native generator; it does not replay/execute them. |
replay_workload(workload=None, ...) | Workload hint | Unsupported; raises NotImplementedError. |
run_test_suite(suite, ...) | An object with async run(context=...) | Runs the supplied suite. |
run_benchmark(profile="mixed", iterations=10, ...) | Requires an explicit callback in operation= | Runs the callback benchmark. |
configure(**values) | Workflow config fields | Updates known fields; unknown values go into context config. |
build() | — | Validates and returns the workflow. |
The convenience functions in storq.workflows.steps construct step objects:
inspect_format, analyze_pages, analyze_wal, create_snapshot,
inject_fault, simulate_crash, verify_recovery, and investigate.
Convenience construction does not change whether a step is implemented.
Execute, events, and lifecycle
await workflow.execute(runtime=None)is the async entry point. It may be limited byWorkflowConfig.timeout.workflow.run()runs synchronously only when there is no active event loop; inside an event loop, useawait workflow.execute().workflow.cancel()requests cancellation.workflow.on(event_type, handler)subscribes;workflow.off(...)unsubscribes.workflow.configure(**values)updates workflow configuration.workflow.pause()andworkflow.resume()request state transitions. They are state controls, not operating-system process controls.workflow.checkpoint()creates an in-memory checkpoint;workflow.save_checkpoint(path)persists one;Workflow.resume(checkpoint, runtime=None, adapter=None)restores from one.workflow.to_dict()returns the workflow definition.
Execution of a workflow that already reached COMPLETED or FAILED is
rejected; use a new workflow or resume from a checkpoint.
Custom steps
Subclass storq.workflows.steps.WorkflowStep and implement async
execute(context). Optional validate(context, result) checks the returned
value. Configure dependencies, timeout, idempotency, and RetryPolicy
carefully. Destructive steps must be non-idempotent so retries cannot repeat
them unintentionally.
Workflow templates
storq.workflows.templates.database_health(database=... or database_path=...)composes format, adapter, page, and optionally WAL steps. Since page/WAL steps currently raiseNotImplementedError, this template is not yet a complete runnable health scan.wal_integrity(...)composes format, WAL, and forensics steps. WAL and forensics workflow steps are unsupported.crash_recovery(..., seed=0, operation_count=100)composes snapshot, generated workload, fault, crash, recovery, and forensics steps. Most of those native steps are unsupported; this is a template of intended orchestration, not a working crash-recovery scenario.
Python test suites
TestCase defines async setup(context), execute(context),
validate(context, result), and teardown(context) hooks. TestSuite.add(case, dependencies=None) registers cases; await suite.run(context=None, capabilities=None) schedules dependency-ready tests, checks required
capabilities, applies timeouts, and returns a SuiteResult.
TestConfig settings:
timeout=300,suite_timeout=Nonemax_workers=1,fail_fast=Falseseed=1,test_isolation=True,preserve_artifacts=Falseretry=RetryConfig(max_attempts=1, delay=0)cleanup_policy:always,success,never, orpreserve-on-failureresource_limits,database_adapter,logging,environment
TestSuite currently does not use all of these fields: notably seed, retry,
test isolation, cleanup policy, and artifact preservation are configuration
metadata rather than implemented setup behavior.
Run the available built-in inspection test
page_integrity() is the only built-in factory that currently performs a
check: it calls native inspect_format() and validates the SQLite header.
The other factories are capability placeholders, as described below.
import asyncio
import sqlite3
from contextlib import closing
import storq
database = "test.sqlite"
with closing(sqlite3.connect(database)) as connection:
connection.execute("CREATE TABLE sample (id INTEGER PRIMARY KEY)")
suite = storq.TestSuite("format checks")
suite.add(storq.page_integrity())
result = asyncio.run(suite.run(context={"database": database}))
print(result.passed, result.failed, result.skipped)
The test reads the database path from context["database"]. The native
extension must be installed for this test to execute. The result counts
summarize test cases; they do not imply that unsupported reliability checks
ran.
Built-in test factory status
page_integrity() creates FormatHeaderTest, which calls
storq.inspect_format() and validates header_valid. It requires the compiled
extension. wal_integrity(), recovery_consistency(),
storage_reliability(), fault_tolerance(), transaction_consistency(), and
concurrency_reliability() produce CapabilityPlaceholderTest cases. They
are skipped as unsupported unless the supplied capability set includes the
required string; if included, the placeholder returns True without running
the named subsystem.
TestCaseRegistry.register/unregister/get/filter manages case factories.
TestStatus values describe lifecycle outcomes; TestResult contains one
case's findings/errors/timing; SuiteResult contains per-case outcomes and
passed/failed/skipped/cancelled summaries.
Serialization and internal helpers
Workflow serialization supports serialize(value), serialize_json(value),
save(value, path), and deserialize(data) through
storq.workflows.serialization. Checkpoint/serialization is only reliable
for supported workflow definitions and serializable step configuration; do
not assume arbitrary Python callbacks or native pointers can be persisted.
