Skip to main content

PostgresWorkflowEventStore

Struct PostgresWorkflowEventStore 

Source
pub struct PostgresWorkflowEventStore { /* private fields */ }
Expand description

PostgreSQL implementation of WorkflowEventStore

Uses a connection pool for efficient database access. Designed for high-throughput with 1000+ concurrent workers.

§Example

let pool = sqlx::PgPool::connect("postgres://localhost/everruns").await?;
let store = everruns_durable::PostgresWorkflowEventStore::new(pool);

Implementations§

Source§

impl PostgresWorkflowEventStore

Source

pub const SCHEMA_SQL: &'static str = "-- everruns-durable PostgreSQL schema.\n--\n-- Applied by `PostgresWorkflowEventStore::migrate`, which runs this whole file in\n-- one transaction under a transaction-scoped advisory lock. Every statement is\n-- idempotent, so it is safe to run on every start-up, concurrently from several\n-- processes, and against a database whose durable tables were already created\n-- by the Everruns server migrations (crates/server/migrations), in which case it\n-- changes nothing.\n--\n-- Objects are created unqualified, in the first schema of the connection\'s\n-- `search_path`. Only built-in PostgreSQL functions are used (no extensions).\n--\n-- This file mirrors the final state the server migrations produce for the\n-- durable tables. `tests/schema_drift_test.rs` fails when the two diverge, so a\n-- server migration that changes a durable table must change this file too. When\n-- evolving it, keep every statement idempotent: add columns with\n-- `ALTER TABLE ... ADD COLUMN IF NOT EXISTS` and indexes with\n-- `CREATE INDEX IF NOT EXISTS`, appended after the CREATE TABLE statements, so\n-- databases created by an older version of this file are brought forward.\n--\n-- `durable_tool_results` is not part of this schema: it belongs to the server\'s\n-- tool-call idempotency storage, and nothing in this crate reads or writes it.\n\n-- UUIDv7 primary-key default. PostgreSQL 18+ ships `uuidv7()`; on older servers,\n-- and when no visible schema already provides one, define a fallback built from\n-- `gen_random_uuid()` (built in since PostgreSQL 13).\nDO $$\nBEGIN\n IF to_regprocedure(\'uuidv7()\') IS NULL THEN\n CREATE FUNCTION uuidv7() RETURNS uuid AS $fn$\n SELECT encode(\n set_bit(\n set_bit(\n overlay(\n uuid_send(gen_random_uuid())\n PLACING substring(\n int8send(floor(extract(epoch FROM clock_timestamp()) * 1000)::bigint)\n FROM 3\n )\n FROM 1 FOR 6\n ),\n 52, 1\n ),\n 53, 1\n ),\n \'hex\'\n )::uuid;\n $fn$ LANGUAGE sql VOLATILE;\n END IF;\nEND\n$$;\n\n-- ============================================\n-- Workflows and their event log\n-- ============================================\n\nCREATE TABLE IF NOT EXISTS durable_workflow_instances (\n id UUID PRIMARY KEY DEFAULT uuidv7(),\n workflow_type TEXT NOT NULL,\n status TEXT NOT NULL DEFAULT \'pending\',\n input JSONB NOT NULL,\n result JSONB,\n error JSONB,\n created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),\n updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),\n started_at TIMESTAMPTZ,\n completed_at TIMESTAMPTZ,\n partition_key INTEGER NOT NULL DEFAULT 0,\n trace_id TEXT,\n span_id TEXT,\n continued_as_new_id UUID REFERENCES durable_workflow_instances(id)\n);\n\nCREATE INDEX IF NOT EXISTS idx_durable_workflow_instances_status\n ON durable_workflow_instances (status);\nCREATE INDEX IF NOT EXISTS idx_durable_workflow_instances_type\n ON durable_workflow_instances (workflow_type);\nCREATE INDEX IF NOT EXISTS idx_durable_workflow_instances_created\n ON durable_workflow_instances (created_at);\nCREATE INDEX IF NOT EXISTS idx_durable_workflow_instances_continued_as_new_id\n ON durable_workflow_instances (continued_as_new_id)\n WHERE continued_as_new_id IS NOT NULL;\n\nCREATE TABLE IF NOT EXISTS durable_workflow_events (\n id BIGSERIAL PRIMARY KEY,\n workflow_id UUID NOT NULL REFERENCES durable_workflow_instances(id) ON DELETE CASCADE,\n sequence_num INTEGER NOT NULL,\n event_type TEXT NOT NULL,\n event_data JSONB NOT NULL,\n created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),\n trace_id TEXT,\n span_id TEXT,\n UNIQUE (workflow_id, sequence_num)\n);\n\nCREATE INDEX IF NOT EXISTS idx_durable_workflow_events_workflow\n ON durable_workflow_events (workflow_id, sequence_num);\n\nCREATE TABLE IF NOT EXISTS durable_workflow_snapshots (\n id BIGSERIAL PRIMARY KEY,\n workflow_id UUID NOT NULL REFERENCES durable_workflow_instances(id) ON DELETE CASCADE,\n sequence_num INTEGER NOT NULL,\n snapshot_data BYTEA NOT NULL,\n created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),\n UNIQUE (workflow_id, sequence_num)\n);\n\nCREATE INDEX IF NOT EXISTS idx_durable_workflow_snapshots_latest\n ON durable_workflow_snapshots (workflow_id, sequence_num DESC);\n\n-- Per-workflow signals served the removed per-step turn workflow; nothing\n-- reads them (server migration drop_turn_workflow_signals).\nDROP TABLE IF EXISTS durable_signals;\n\n-- ============================================\n-- Task queue and dead letters\n-- ============================================\n\nCREATE TABLE IF NOT EXISTS durable_task_queue (\n id UUID PRIMARY KEY DEFAULT uuidv7(),\n workflow_id UUID REFERENCES durable_workflow_instances(id) ON DELETE CASCADE,\n activity_id TEXT NOT NULL,\n activity_type TEXT NOT NULL,\n input JSONB NOT NULL,\n options JSONB NOT NULL,\n status TEXT NOT NULL DEFAULT \'pending\',\n priority INTEGER NOT NULL DEFAULT 0,\n scheduled_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),\n visible_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),\n claimed_by TEXT,\n claimed_at TIMESTAMPTZ,\n heartbeat_at TIMESTAMPTZ,\n attempt INTEGER NOT NULL DEFAULT 0,\n max_attempts INTEGER NOT NULL,\n last_error TEXT,\n schedule_to_start_timeout_ms BIGINT NOT NULL,\n start_to_close_timeout_ms BIGINT NOT NULL,\n heartbeat_timeout_ms BIGINT,\n trace_id TEXT,\n span_id TEXT,\n created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),\n progress_token BIGINT,\n no_progress_count INTEGER NOT NULL DEFAULT 0\n);\n-- Named task queue (`ActivityOptions::queue`); NULL is the default queue.\n-- Server migration 178.\nALTER TABLE durable_task_queue ADD COLUMN IF NOT EXISTS queue TEXT;\n\nCREATE INDEX IF NOT EXISTS idx_durable_task_queue_pending\n ON durable_task_queue (priority DESC, visible_at, activity_type)\n WHERE status = \'pending\';\nCREATE INDEX IF NOT EXISTS idx_durable_task_queue_claimed\n ON durable_task_queue (claimed_by, heartbeat_at)\n WHERE status = \'claimed\';\nCREATE INDEX IF NOT EXISTS idx_durable_task_queue_stale_reclaim\n ON durable_task_queue (heartbeat_at)\n WHERE status = \'claimed\';\nCREATE INDEX IF NOT EXISTS idx_durable_task_queue_standalone\n ON durable_task_queue (created_at DESC)\n WHERE workflow_id IS NULL;\nCREATE INDEX IF NOT EXISTS idx_durable_task_queue_workflow\n ON durable_task_queue (workflow_id);\n-- Task listings order by created_at; worker listings aggregate by claimed_by.\n-- Server migrations 208 and 209.\nCREATE INDEX IF NOT EXISTS idx_durable_task_queue_created_at\n ON durable_task_queue (created_at);\nCREATE INDEX IF NOT EXISTS idx_durable_task_queue_claimed_by\n ON durable_task_queue (claimed_by)\n WHERE claimed_by IS NOT NULL;\n-- The removed per-step turn workflow\'s enqueue dedupe index (server migration\n-- drop_turn_workflow_signals).\nDROP INDEX IF EXISTS idx_durable_task_queue_waiting_turn_resolution;\n\nCREATE TABLE IF NOT EXISTS durable_dead_letter_queue (\n id UUID PRIMARY KEY DEFAULT uuidv7(),\n original_task_id UUID NOT NULL,\n workflow_id UUID REFERENCES durable_workflow_instances(id) ON DELETE CASCADE,\n activity_id TEXT NOT NULL,\n activity_type TEXT NOT NULL,\n input JSONB NOT NULL,\n attempts INTEGER NOT NULL,\n last_error TEXT NOT NULL,\n error_history JSONB NOT NULL,\n dead_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),\n requeued_at TIMESTAMPTZ,\n requeue_count INTEGER NOT NULL DEFAULT 0\n);\n\n-- The dead task\'s activity options (server migration 181), so a requeue keeps\n-- its queue and retry settings. NULL for rows dead before it.\nALTER TABLE durable_dead_letter_queue ADD COLUMN IF NOT EXISTS options JSONB;\n\nCREATE INDEX IF NOT EXISTS idx_durable_dlq_activity_type\n ON durable_dead_letter_queue (activity_type);\nCREATE INDEX IF NOT EXISTS idx_durable_dlq_dead_at\n ON durable_dead_letter_queue (dead_at);\nCREATE INDEX IF NOT EXISTS idx_durable_dlq_workflow\n ON durable_dead_letter_queue (workflow_id);\n\n-- ============================================\n-- Workers and circuit breakers\n-- ============================================\n\nCREATE TABLE IF NOT EXISTS durable_workers (\n id TEXT PRIMARY KEY,\n worker_group TEXT NOT NULL,\n activity_types TEXT[] NOT NULL,\n max_concurrency INTEGER NOT NULL,\n current_load INTEGER NOT NULL DEFAULT 0,\n status TEXT NOT NULL DEFAULT \'active\',\n started_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),\n last_heartbeat_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),\n accepting_tasks BOOLEAN NOT NULL DEFAULT TRUE,\n backpressure_reason TEXT,\n hostname TEXT,\n version TEXT,\n metadata JSONB\n);\n\nCREATE INDEX IF NOT EXISTS idx_durable_workers_group\n ON durable_workers (worker_group);\nCREATE INDEX IF NOT EXISTS idx_durable_workers_heartbeat\n ON durable_workers (last_heartbeat_at);\nCREATE INDEX IF NOT EXISTS idx_durable_workers_status\n ON durable_workers (status)\n WHERE status = \'active\';\n\nCREATE TABLE IF NOT EXISTS durable_circuit_breaker_state (\n key TEXT PRIMARY KEY,\n state TEXT NOT NULL DEFAULT \'closed\',\n failure_count INTEGER NOT NULL DEFAULT 0,\n success_count INTEGER NOT NULL DEFAULT 0,\n last_failure_at TIMESTAMPTZ,\n opened_at TIMESTAMPTZ,\n half_open_at TIMESTAMPTZ,\n updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()\n);\n\n-- ============================================\n-- Schedules\n-- ============================================\n\nCREATE TABLE IF NOT EXISTS durable_schedules (\n id UUID PRIMARY KEY DEFAULT uuidv7(),\n name TEXT NOT NULL UNIQUE,\n description TEXT,\n cron_expression TEXT NOT NULL,\n timezone TEXT NOT NULL DEFAULT \'UTC\',\n target_type TEXT NOT NULL CHECK (target_type IN (\'workflow\', \'activity\')),\n target_name TEXT NOT NULL,\n target_input JSONB NOT NULL DEFAULT \'{}\',\n enabled BOOLEAN NOT NULL DEFAULT TRUE,\n max_concurrent INTEGER,\n catch_up_missed BOOLEAN NOT NULL DEFAULT FALSE,\n max_catch_up INTEGER DEFAULT 1,\n retry_policy JSONB,\n last_triggered_at TIMESTAMPTZ,\n next_trigger_at TIMESTAMPTZ,\n claimed_by TEXT,\n claimed_at TIMESTAMPTZ,\n created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),\n updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()\n);\n\nCREATE INDEX IF NOT EXISTS idx_durable_schedules_polling\n ON durable_schedules (next_trigger_at)\n INCLUDE (claimed_by, claimed_at)\n WHERE enabled = TRUE;\n\nCREATE TABLE IF NOT EXISTS durable_schedule_executions (\n id UUID PRIMARY KEY DEFAULT uuidv7(),\n schedule_id UUID NOT NULL REFERENCES durable_schedules(id) ON DELETE CASCADE,\n scheduled_at TIMESTAMPTZ NOT NULL,\n started_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),\n completed_at TIMESTAMPTZ,\n status TEXT NOT NULL DEFAULT \'running\'\n CHECK (status IN (\'pending\', \'running\', \'completed\', \'failed\', \'skipped\')),\n workflow_id UUID,\n task_id UUID,\n error TEXT,\n duration_ms INTEGER,\n created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()\n);\n\nCREATE INDEX IF NOT EXISTS idx_durable_schedule_executions_schedule\n ON durable_schedule_executions (schedule_id, created_at DESC);\nCREATE INDEX IF NOT EXISTS idx_durable_schedule_executions_running\n ON durable_schedule_executions (schedule_id)\n WHERE status = \'running\';\n\nCREATE TABLE IF NOT EXISTS durable_scheduler_instances (\n instance_id TEXT PRIMARY KEY,\n started_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),\n last_heartbeat_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),\n schedules_processed BIGINT NOT NULL DEFAULT 0,\n hostname TEXT,\n version TEXT\n);\n\nCREATE INDEX IF NOT EXISTS idx_durable_scheduler_instances_heartbeat\n ON durable_scheduler_instances (last_heartbeat_at);\n\n-- ============================================\n-- Triggers\n-- ============================================\n\nCREATE OR REPLACE FUNCTION update_durable_updated_at()\nRETURNS TRIGGER AS $$\nBEGIN\n NEW.updated_at = NOW();\n RETURN NEW;\nEND;\n$$ LANGUAGE plpgsql;\n\nCREATE OR REPLACE TRIGGER trigger_durable_workflow_instances_updated_at\n BEFORE UPDATE ON durable_workflow_instances\n FOR EACH ROW EXECUTE FUNCTION update_durable_updated_at();\n\nCREATE OR REPLACE TRIGGER trigger_durable_schedules_updated_at\n BEFORE UPDATE ON durable_schedules\n FOR EACH ROW EXECUTE FUNCTION update_durable_updated_at();\n\n-- Wake idle workers (LISTEN task_available) when a task becomes claimable.\nCREATE OR REPLACE FUNCTION notify_task_available()\nRETURNS TRIGGER AS $$\nBEGIN\n -- Notify with activity_type as payload for filtering. A named queue\'s\n -- task wakes no default-queue listener: none of them could claim it.\n IF NEW.queue IS NULL THEN\n PERFORM pg_notify(\'task_available\', NEW.activity_type);\n END IF;\n RETURN NEW;\nEND;\n$$ LANGUAGE plpgsql;\n\nCREATE OR REPLACE TRIGGER task_enqueue_notify\n AFTER INSERT ON durable_task_queue\n FOR EACH ROW\n WHEN (NEW.status = \'pending\')\n EXECUTE FUNCTION notify_task_available();\n\nCREATE OR REPLACE TRIGGER task_pending_notify\n AFTER UPDATE ON durable_task_queue\n FOR EACH ROW\n WHEN (OLD.status <> \'pending\' AND NEW.status = \'pending\')\n EXECUTE FUNCTION notify_task_available();\n\n-- ============================================\n-- Health counters\n-- ============================================\n-- Cumulative task/workflow totals read by `DurableAdmin::get_system_health`.\n-- Statement-level AFTER triggers apply one aggregated delta per statement, so\n-- the sum of a counter\'s rows always equals the COUNT(*) it replaces and reads\n-- stay O(1). Each counter has 16 shard rows and a trigger writes the shard\n-- picked by `pg_backend_pid() % 16`: one row per counter would be locked by\n-- every claim and hand-off until commit, serializing them all. A single shard\n-- can go negative, so only the sum is meaningful.\n\nCREATE TABLE IF NOT EXISTS durable_stat_counters (\n name TEXT NOT NULL,\n value BIGINT NOT NULL DEFAULT 0,\n shard SMALLINT NOT NULL DEFAULT 0,\n PRIMARY KEY (name, shard)\n);\n\n-- Databases that took the unsharded table: same steps as server migration 182.\nDO $$\nBEGIN\n IF NOT EXISTS (\n SELECT 1 FROM information_schema.columns\n WHERE table_schema = current_schema()\n AND table_name = \'durable_stat_counters\'\n AND column_name = \'shard\'\n ) THEN\n ALTER TABLE durable_stat_counters DROP CONSTRAINT durable_stat_counters_pkey;\n ALTER TABLE durable_stat_counters DROP CONSTRAINT IF EXISTS durable_stat_counters_value_check;\n ALTER TABLE durable_stat_counters ADD COLUMN shard SMALLINT NOT NULL DEFAULT 0;\n ALTER TABLE durable_stat_counters ADD PRIMARY KEY (name, shard);\n END IF;\nEND\n$$;\n\nCREATE OR REPLACE FUNCTION durable_task_stat_counters()\nRETURNS TRIGGER AS $$\nDECLARE\n d_completed BIGINT := 0;\n d_failed BIGINT := 0;\n d_started BIGINT := 0;\n my_shard SMALLINT := pg_backend_pid() % 16;\nBEGIN\n IF TG_OP IN (\'INSERT\', \'UPDATE\') THEN\n SELECT\n count(*) FILTER (WHERE status = \'completed\'),\n count(*) FILTER (WHERE status IN (\'failed\', \'dead\')),\n count(*) FILTER (WHERE claimed_at IS NOT NULL)\n INTO d_completed, d_failed, d_started\n FROM new_rows;\n END IF;\n\n IF TG_OP IN (\'UPDATE\', \'DELETE\') THEN\n d_completed := d_completed - (SELECT count(*) FROM old_rows WHERE status = \'completed\');\n d_failed := d_failed - (SELECT count(*) FROM old_rows WHERE status IN (\'failed\', \'dead\'));\n d_started := d_started - (SELECT count(*) FROM old_rows WHERE claimed_at IS NOT NULL);\n END IF;\n\n IF d_completed <> 0 THEN\n UPDATE durable_stat_counters SET value = value + d_completed WHERE name = \'tasks_completed\' AND shard = my_shard;\n END IF;\n IF d_failed <> 0 THEN\n UPDATE durable_stat_counters SET value = value + d_failed WHERE name = \'tasks_failed\' AND shard = my_shard;\n END IF;\n IF d_started <> 0 THEN\n UPDATE durable_stat_counters SET value = value + d_started WHERE name = \'tasks_started\' AND shard = my_shard;\n END IF;\n\n RETURN NULL; -- AFTER trigger: return value is ignored\nEND;\n$$ LANGUAGE plpgsql;\n\nCREATE OR REPLACE FUNCTION durable_workflow_stat_counters()\nRETURNS TRIGGER AS $$\nDECLARE\n d_completed BIGINT := 0;\n d_failed BIGINT := 0;\n d_started BIGINT := 0;\n my_shard SMALLINT := pg_backend_pid() % 16;\nBEGIN\n IF TG_OP IN (\'INSERT\', \'UPDATE\') THEN\n SELECT\n count(*) FILTER (WHERE status = \'completed\'),\n count(*) FILTER (WHERE status IN (\'failed\', \'cancelled\')),\n count(*) FILTER (WHERE started_at IS NOT NULL)\n INTO d_completed, d_failed, d_started\n FROM new_rows;\n END IF;\n\n IF TG_OP IN (\'UPDATE\', \'DELETE\') THEN\n d_completed := d_completed - (SELECT count(*) FROM old_rows WHERE status = \'completed\');\n d_failed := d_failed - (SELECT count(*) FROM old_rows WHERE status IN (\'failed\', \'cancelled\'));\n d_started := d_started - (SELECT count(*) FROM old_rows WHERE started_at IS NOT NULL);\n END IF;\n\n IF d_completed <> 0 THEN\n UPDATE durable_stat_counters SET value = value + d_completed WHERE name = \'workflows_completed\' AND shard = my_shard;\n END IF;\n IF d_failed <> 0 THEN\n UPDATE durable_stat_counters SET value = value + d_failed WHERE name = \'workflows_failed\' AND shard = my_shard;\n END IF;\n IF d_started <> 0 THEN\n UPDATE durable_stat_counters SET value = value + d_started WHERE name = \'workflows_started\' AND shard = my_shard;\n END IF;\n\n RETURN NULL;\nEND;\n$$ LANGUAGE plpgsql;\n\nCREATE OR REPLACE TRIGGER durable_task_stat_counters_insert\n AFTER INSERT ON durable_task_queue\n REFERENCING NEW TABLE AS new_rows\n FOR EACH STATEMENT EXECUTE FUNCTION durable_task_stat_counters();\n\nCREATE OR REPLACE TRIGGER durable_task_stat_counters_update\n AFTER UPDATE ON durable_task_queue\n REFERENCING OLD TABLE AS old_rows NEW TABLE AS new_rows\n FOR EACH STATEMENT EXECUTE FUNCTION durable_task_stat_counters();\n\nCREATE OR REPLACE TRIGGER durable_task_stat_counters_delete\n AFTER DELETE ON durable_task_queue\n REFERENCING OLD TABLE AS old_rows\n FOR EACH STATEMENT EXECUTE FUNCTION durable_task_stat_counters();\n\nCREATE OR REPLACE TRIGGER durable_workflow_stat_counters_insert\n AFTER INSERT ON durable_workflow_instances\n REFERENCING NEW TABLE AS new_rows\n FOR EACH STATEMENT EXECUTE FUNCTION durable_workflow_stat_counters();\n\nCREATE OR REPLACE TRIGGER durable_workflow_stat_counters_update\n AFTER UPDATE ON durable_workflow_instances\n REFERENCING OLD TABLE AS old_rows NEW TABLE AS new_rows\n FOR EACH STATEMENT EXECUTE FUNCTION durable_workflow_stat_counters();\n\nCREATE OR REPLACE TRIGGER durable_workflow_stat_counters_delete\n AFTER DELETE ON durable_workflow_instances\n REFERENCING OLD TABLE AS old_rows\n FOR EACH STATEMENT EXECUTE FUNCTION durable_workflow_stat_counters();\n\n-- Seed the counters from current rows into shard 0. The trigger statements\n-- above hold SHARE ROW EXCLUSIVE locks on both tables until commit, so no write\n-- slips between these counts and the triggers. Existing counter rows are kept.\nINSERT INTO durable_stat_counters (name, value) VALUES\n (\'tasks_completed\', (SELECT COUNT(*) FROM durable_task_queue WHERE status = \'completed\')),\n (\'tasks_failed\', (SELECT COUNT(*) FROM durable_task_queue WHERE status IN (\'failed\', \'dead\'))),\n (\'tasks_started\', (SELECT COUNT(*) FROM durable_task_queue WHERE claimed_at IS NOT NULL)),\n (\'workflows_completed\', (SELECT COUNT(*) FROM durable_workflow_instances WHERE status = \'completed\')),\n (\'workflows_failed\', (SELECT COUNT(*) FROM durable_workflow_instances WHERE status IN (\'failed\', \'cancelled\'))),\n (\'workflows_started\', (SELECT COUNT(*) FROM durable_workflow_instances WHERE started_at IS NOT NULL))\nON CONFLICT (name, shard) DO NOTHING;\n\nINSERT INTO durable_stat_counters (name, shard, value)\nSELECT counters.name, shards.shard, 0\nFROM (SELECT DISTINCT name FROM durable_stat_counters) counters\nCROSS JOIN generate_series(1, 15) AS shards(shard)\nON CONFLICT (name, shard) DO NOTHING;\n"

The idempotent SQL that migrate applies.

Exposed for applications that manage schema with their own migration tool: copy it into a migration instead of calling migrate at start-up.

Source

pub async fn migrate(pool: &PgPool) -> Result<(), Error>

Create or update the durable tables, indexes, functions and triggers.

Safe to call on every start-up: every statement is idempotent, the whole schema is applied in one transaction, concurrent callers serialize on an advisory lock, and a database that already took this exact schema is only read, not locked. Apply a new schema version before traffic that uses it, as with any migration. A database already migrated by the Everruns server is left unchanged. Objects land in the first schema of the connection’s search_path, normally public.

Requires PostgreSQL 14 or newer and no extensions.

§Example
use everruns_durable::PostgresWorkflowEventStore;

let pool = sqlx::PgPool::connect("postgres://localhost/my_app").await?;
PostgresWorkflowEventStore::migrate(&pool).await?;
let store = PostgresWorkflowEventStore::new(pool);
Source

pub async fn connect(url: &str) -> Result<Self, Error>

Connect to the database at url, apply the schema with migrate, and return a store over the new pool.

The one-call start for an application that keeps no pool of its own, so it never touches the database driver. An application that manages its pool or its schema itself builds the store with new instead.

§Example
use everruns_durable::PostgresWorkflowEventStore;

let store = PostgresWorkflowEventStore::connect("postgres://localhost/my_app").await?;
Source§

impl PostgresWorkflowEventStore

Source

pub fn new(pool: PgPool) -> Self

Create a new PostgreSQL store with the given connection pool

Source

pub fn pool(&self) -> &PgPool

Get a reference to the connection pool

Source

pub async fn start_workflow_with_task( &self, workflow_id: Uuid, workflow_type: &str, input: Value, task: TaskDefinition, ) -> Result<Uuid, StoreError>

Create a workflow, write its initial events, and enqueue the first task in one transaction. This is the hot path for starting a new workflow run.

Trait Implementations§

Source§

impl CircuitBreakers for PostgresWorkflowEventStore

Source§

fn create_circuit_breaker<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, key: &'life1 str, config: &'life2 CircuitBreakerConfig, ) -> Pin<Box<dyn Future<Output = Result<(), StoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Create a circuit breaker
Source§

fn get_circuit_breaker<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Option<CircuitBreakerState>, StoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Get circuit breaker state
Source§

fn update_circuit_breaker<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 str, state: CircuitState, failure_count: u32, success_count: u32, ) -> Pin<Box<dyn Future<Output = Result<(), StoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Update circuit breaker state
Source§

fn list_circuit_breakers<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Vec<CircuitBreakerState>, StoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

List all circuit breakers
Source§

fn force_open_circuit_breaker<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<(), StoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Force a circuit breaker to open (admin operation)
Source§

fn force_close_circuit_breaker<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<(), StoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Force a circuit breaker to close (admin operation)
Source§

fn delete_circuit_breaker<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<(), StoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Delete a circuit breaker (reset to default)
Source§

impl Clone for PostgresWorkflowEventStore

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl DeadLetters for PostgresWorkflowEventStore

Source§

fn move_to_dlq<'life0, 'async_trait>( &'life0 self, task_id: Uuid, error_history: Vec<String>, ) -> Pin<Box<dyn Future<Output = Result<(), StoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Move task to DLQ
Source§

fn requeue_from_dlq<'life0, 'async_trait>( &'life0 self, dlq_id: Uuid, ) -> Pin<Box<dyn Future<Output = Result<Uuid, StoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Requeue task from DLQ
Source§

fn list_dlq<'life0, 'async_trait>( &'life0 self, filter: DlqFilter, pagination: Pagination, ) -> Pin<Box<dyn Future<Output = Result<Vec<DlqEntry>, StoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

List DLQ entries
Source§

impl DurableAdmin for PostgresWorkflowEventStore

Source§

fn count_active_workflows<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<i64, StoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Count active (non-terminal) workflows
Source§

fn get_workflow_extended<'life0, 'async_trait>( &'life0 self, workflow_id: Uuid, ) -> Pin<Box<dyn Future<Output = Result<Option<WorkflowInfoExtended>, StoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Direct lookup of a single workflow by id, returning the same WorkflowInfoExtended shape as list_workflows. Returns Ok(None) when the workflow does not exist. Read more
Source§

fn list_workflows<'life0, 'async_trait>( &'life0 self, filter: WorkflowFilter, pagination: Pagination, ) -> Pin<Box<dyn Future<Output = Result<Vec<WorkflowInfoExtended>, StoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

List workflows with filtering and pagination
Source§

fn get_system_health<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<SystemHealth, StoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Get system health summary
Source§

fn get_workflow_events<'life0, 'async_trait>( &'life0 self, workflow_id: Uuid, ) -> Pin<Box<dyn Future<Output = Result<Vec<WorkflowEventInfo>, StoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Get workflow events
Source§

fn count_workflow_events<'life0, 'async_trait>( &'life0 self, workflow_id: Uuid, ) -> Pin<Box<dyn Future<Output = Result<i64, StoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Count workflow events without materializing them. Uses SELECT COUNT(*) in PostgreSQL; falls back to load_events().len() by default.
Source§

impl EventLog for PostgresWorkflowEventStore

Source§

fn create_workflow<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, workflow_id: Uuid, workflow_type: &'life1 str, input: Value, trace_context: Option<&'life2 TraceContext>, ) -> Pin<Box<dyn Future<Output = Result<(), StoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Create a new workflow instance
Source§

fn get_workflow_status<'life0, 'async_trait>( &'life0 self, workflow_id: Uuid, ) -> Pin<Box<dyn Future<Output = Result<WorkflowStatus, StoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Get workflow status
Source§

fn get_workflow_info<'life0, 'async_trait>( &'life0 self, workflow_id: Uuid, ) -> Pin<Box<dyn Future<Output = Result<WorkflowInfo, StoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Get full workflow info
Source§

fn append_events<'life0, 'async_trait>( &'life0 self, workflow_id: Uuid, expected_sequence: i32, events: Vec<WorkflowEvent>, ) -> Pin<Box<dyn Future<Output = Result<i32, StoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Append events to a workflow (with optimistic concurrency) Read more
Source§

fn load_events<'life0, 'async_trait>( &'life0 self, workflow_id: Uuid, ) -> Pin<Box<dyn Future<Output = Result<Vec<(i32, WorkflowEvent)>, StoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Load all events for a workflow (for replay)
Source§

fn count_events<'life0, 'async_trait>( &'life0 self, workflow_id: Uuid, ) -> Pin<Box<dyn Future<Output = Result<usize, StoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Count events for a workflow without materializing the replay payload. Read more
Source§

fn count_events_after<'life0, 'async_trait>( &'life0 self, workflow_id: Uuid, after_sequence: i32, ) -> Pin<Box<dyn Future<Output = Result<usize, StoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Count events after a given sequence number without materializing them. Read more
Source§

fn load_events_after<'life0, 'async_trait>( &'life0 self, workflow_id: Uuid, after_sequence: i32, ) -> Pin<Box<dyn Future<Output = Result<Vec<(i32, WorkflowEvent)>, StoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Load events for a workflow starting after a given sequence number. Read more
Source§

fn save_snapshot<'life0, 'async_trait>( &'life0 self, workflow_id: Uuid, sequence_num: i32, snapshot_data: Vec<u8>, ) -> Pin<Box<dyn Future<Output = Result<(), StoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Save a workflow state snapshot at the given sequence number. Read more
Source§

fn load_latest_snapshot<'life0, 'async_trait>( &'life0 self, workflow_id: Uuid, ) -> Pin<Box<dyn Future<Output = Result<Option<WorkflowSnapshot>, StoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Load the latest snapshot for a workflow, if any. Read more
Source§

fn delete_snapshots<'life0, 'async_trait>( &'life0 self, workflow_id: Uuid, ) -> Pin<Box<dyn Future<Output = Result<(), StoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Delete all snapshots for a workflow (cleanup on workflow deletion).
Source§

fn update_workflow_status<'life0, 'async_trait>( &'life0 self, workflow_id: Uuid, status: WorkflowStatus, result: Option<Value>, error: Option<WorkflowError>, ) -> Pin<Box<dyn Future<Output = Result<(), StoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Update workflow status
Source§

fn try_fail_workflow<'life0, 'async_trait>( &'life0 self, workflow_id: Uuid, error: WorkflowError, ) -> Pin<Box<dyn Future<Output = Result<bool, StoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Atomically transition a running workflow to failed. Read more
Source§

fn try_start_new_run<'life0, 'async_trait>( &'life0 self, workflow_id: Uuid, ) -> Pin<Box<dyn Future<Output = Result<bool, StoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Atomically start a new run of a long-lived workflow, unless one is already active. Read more
Source§

fn cancel_workflow<'life0, 'async_trait>( &'life0 self, workflow_id: Uuid, ) -> Pin<Box<dyn Future<Output = Result<(), StoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Cancel a workflow
Source§

fn continue_as_new<'life0, 'life1, 'async_trait>( &'life0 self, old_workflow_id: Uuid, workflow_type: &'life1 str, input: Value, snapshot_data: Vec<u8>, ) -> Pin<Box<dyn Future<Output = Result<Uuid, StoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Continue a workflow as a new workflow (history rollover). Read more
Source§

impl Schedules for PostgresWorkflowEventStore

Source§

fn schedule_transaction_pool(&self) -> Option<PgPool>

Pool whose schedule configuration joins a host command transaction.
Source§

fn create_schedule<'life0, 'async_trait>( &'life0 self, schedule: CreateScheduleRow, ) -> Pin<Box<dyn Future<Output = Result<Uuid, StoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Create a new schedule
Source§

fn get_schedule<'life0, 'async_trait>( &'life0 self, id: Uuid, ) -> Pin<Box<dyn Future<Output = Result<ScheduleRow, StoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Get a schedule by ID
Source§

fn list_schedules<'life0, 'async_trait>( &'life0 self, filter: ScheduleFilter, pagination: Pagination, ) -> Pin<Box<dyn Future<Output = Result<Vec<ScheduleRow>, StoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

List schedules with filtering and pagination
Source§

fn count_schedules<'life0, 'async_trait>( &'life0 self, filter: ScheduleFilter, ) -> Pin<Box<dyn Future<Output = Result<u64, StoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Count schedules matching filter
Source§

fn update_schedule<'life0, 'async_trait>( &'life0 self, id: Uuid, update: UpdateSchedule, ) -> Pin<Box<dyn Future<Output = Result<(), StoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Update a schedule
Source§

fn delete_schedule<'life0, 'async_trait>( &'life0 self, id: Uuid, ) -> Pin<Box<dyn Future<Output = Result<(), StoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Delete a schedule
Source§

fn claim_due_schedules<'life0, 'life1, 'async_trait>( &'life0 self, scheduler_id: &'life1 str, limit: u32, ) -> Pin<Box<dyn Future<Output = Result<Vec<ScheduleRow>, StoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Claim due schedules for processing (uses SKIP LOCKED for multi-instance) Returns schedules with next_trigger_at <= now
Source§

fn update_next_trigger<'life0, 'async_trait>( &'life0 self, id: Uuid, next: DateTime<Utc>, ) -> Pin<Box<dyn Future<Output = Result<(), StoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Update next trigger time after successful trigger
Source§

fn skip_schedule_trigger<'life0, 'async_trait>( &'life0 self, id: Uuid, ) -> Pin<Box<dyn Future<Output = Result<(), StoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Skip a schedule trigger (e.g., max_concurrent reached)
Source§

fn release_schedule<'life0, 'async_trait>( &'life0 self, id: Uuid, ) -> Pin<Box<dyn Future<Output = Result<(), StoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Release a claimed schedule (e.g., on scheduler shutdown)
Source§

fn create_schedule_execution<'life0, 'async_trait>( &'life0 self, schedule_id: Uuid, scheduled_at: DateTime<Utc>, ) -> Pin<Box<dyn Future<Output = Result<Uuid, StoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Create a schedule execution record
Source§

fn get_schedule_execution<'life0, 'async_trait>( &'life0 self, id: Uuid, ) -> Pin<Box<dyn Future<Output = Result<ScheduleExecutionRow, StoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Get a schedule execution by ID
Source§

fn complete_schedule_execution<'life0, 'async_trait>( &'life0 self, execution_id: Uuid, target_id: Uuid, is_workflow: bool, ) -> Pin<Box<dyn Future<Output = Result<(), StoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Complete a schedule execution successfully
Source§

fn fail_schedule_execution<'life0, 'life1, 'async_trait>( &'life0 self, execution_id: Uuid, error: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<(), StoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Fail a schedule execution
Source§

fn skip_schedule_execution<'life0, 'life1, 'async_trait>( &'life0 self, execution_id: Uuid, reason: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<(), StoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Skip a schedule execution
Source§

fn list_schedule_executions<'life0, 'async_trait>( &'life0 self, filter: ScheduleExecutionFilter, pagination: Pagination, ) -> Pin<Box<dyn Future<Output = Result<Vec<ScheduleExecutionRow>, StoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

List executions for a schedule
Source§

fn count_running_executions<'life0, 'async_trait>( &'life0 self, schedule_id: Uuid, ) -> Pin<Box<dyn Future<Output = Result<u32, StoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Count running executions for a schedule (for max_concurrent check)
Source§

fn last_scheduled_task_pending<'life0, 'async_trait>( &'life0 self, schedule_id: Uuid, ) -> Pin<Box<dyn Future<Output = Result<bool, StoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Whether the task this schedule last enqueued is still waiting to be claimed. The scheduler skips a trigger while it is, so a schedule nothing claims holds one pending task instead of one per trigger.
Source§

fn get_schedule_stats<'life0, 'async_trait>( &'life0 self, schedule_id: Uuid, ) -> Pin<Box<dyn Future<Output = Result<ScheduleStats, StoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Get schedule statistics
Source§

fn register_scheduler_instance<'life0, 'async_trait>( &'life0 self, instance: SchedulerInstanceInfo, ) -> Pin<Box<dyn Future<Output = Result<(), StoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Register a scheduler instance
Source§

fn heartbeat_scheduler_instance<'life0, 'life1, 'async_trait>( &'life0 self, instance_id: &'life1 str, schedules_processed: u64, ) -> Pin<Box<dyn Future<Output = Result<(), StoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Update scheduler instance heartbeat
Source§

fn list_scheduler_instances<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Vec<SchedulerInstanceInfo>, StoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

List scheduler instances
Source§

fn deregister_scheduler_instance<'life0, 'life1, 'async_trait>( &'life0 self, instance_id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<(), StoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Deregister a scheduler instance
Source§

impl TaskQueue for PostgresWorkflowEventStore

Source§

fn enqueue_task<'life0, 'async_trait>( &'life0 self, task: TaskDefinition, ) -> Pin<Box<dyn Future<Output = Result<Uuid, StoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Enqueue an activity task
Source§

fn claim_queue_tasks<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, worker_id: &'life1 str, queue: Option<&'life2 str>, activity_types: &'life3 [String], max_tasks: usize, ) -> Pin<Box<dyn Future<Output = Result<Vec<ClaimedTask>, StoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Claim up to max_tasks pending tasks of activity_types from one task queue: the named one, or the default queue for None (ActivityOptions::queue). A claim never takes another queue’s tasks. Read more
Source§

fn heartbeat_task<'life0, 'life1, 'async_trait>( &'life0 self, task_id: Uuid, worker_id: &'life1 str, _details: Option<Value>, ) -> Pin<Box<dyn Future<Output = Result<HeartbeatResponse, StoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Record task heartbeat
Source§

fn complete_task<'life0, 'life1, 'async_trait>( &'life0 self, task_id: Uuid, worker_id: &'life1 str, _result: Value, ) -> Pin<Box<dyn Future<Output = Result<(), StoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Complete a task successfully Read more
Source§

fn fail_task_with_retry<'life0, 'life1, 'async_trait>( &'life0 self, task_id: Uuid, error: &'life1 str, retryable: bool, ) -> Pin<Box<dyn Future<Output = Result<TaskFailureOutcome, StoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Fail a task, optionally bypassing retries for deterministic failures.
Source§

fn cancel_pending_tasks_for_workflow<'life0, 'async_trait>( &'life0 self, workflow_id: Uuid, ) -> Pin<Box<dyn Future<Output = Result<u64, StoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Cancel all pending (unclaimed) tasks for a workflow. Read more
Source§

fn get_task<'life0, 'async_trait>( &'life0 self, task_id: Uuid, ) -> Pin<Box<dyn Future<Output = Result<TaskInfo, StoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Get task info by ID
Source§

fn reclaim_stale_tasks<'life0, 'async_trait>( &'life0 self, stale_threshold: Duration, ) -> Pin<Box<dyn Future<Output = Result<ReclaimResult, StoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Find and reclaim stale tasks (no heartbeat)
Source§

fn list_tasks<'life0, 'async_trait>( &'life0 self, filter: TaskFilter, pagination: Pagination, ) -> Pin<Box<dyn Future<Output = Result<Vec<TaskInfo>, StoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

List tasks with filtering and pagination
Source§

fn claim_task<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, worker_id: &'life1 str, activity_types: &'life2 [String], max_tasks: usize, ) -> Pin<Box<dyn Future<Output = Result<Vec<ClaimedTask>, StoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Claim tasks of the default queue for execution; see claim_queue_tasks.
Source§

fn fail_task<'life0, 'life1, 'async_trait>( &'life0 self, task_id: Uuid, error: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<TaskFailureOutcome, StoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Fail a task using its normal retry policy.
Source§

impl WorkerRegistry for PostgresWorkflowEventStore

Source§

fn register_worker<'life0, 'async_trait>( &'life0 self, worker: WorkerInfo, ) -> Pin<Box<dyn Future<Output = Result<(), StoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Register a worker
Source§

fn worker_heartbeat<'life0, 'life1, 'async_trait>( &'life0 self, worker_id: &'life1 str, current_load: usize, accepting_tasks: bool, ) -> Pin<Box<dyn Future<Output = Result<WorkerHeartbeat, StoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Update worker heartbeat and load, and report whether it is draining
Source§

fn list_workers<'life0, 'async_trait>( &'life0 self, filter: WorkerFilter, ) -> Pin<Box<dyn Future<Output = Result<Vec<WorkerInfo>, StoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Get all active workers
Source§

fn deregister_worker<'life0, 'life1, 'async_trait>( &'life0 self, worker_id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<usize, StoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Deregister a worker and reclaim all tasks claimed by it Returns the number of tasks that were reclaimed
Source§

fn get_capacity_snapshot<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<CapacitySnapshot, StoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Get a snapshot of total system worker capacity. Used by workers to compute fair-share claim limits.
Source§

fn drain_worker<'life0, 'life1, 'async_trait>( &'life0 self, worker_id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<(), StoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Drain a worker (set status to draining, stop accepting new tasks)
Source§

fn resume_worker<'life0, 'life1, 'async_trait>( &'life0 self, worker_id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<(), StoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Resume a draining worker (set status back to active, start accepting new tasks)
Source§

fn record_worker_checks<'life0, 'life1, 'async_trait>( &'life0 self, worker_id: &'life1 str, checks: Value, ) -> Pin<Box<dyn Future<Output = Result<(), StoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Keep the worker’s report on its own setup (egress proxy reachable, control-plane connection encrypted, …), replacing the previous one. Operators read it back through WorkerInfo::self_checks. A store with no operator view may keep nothing.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> WorkflowEventStore for T