• TehPers ( TehPers@beehaw.org ) 
    link
    fedilink
    English
    arrow-up
    3
    ·
    16 hours ago

    The article fails to actually explain how to do durable workflows in Postgres:

    In a Postgres-backed durable workflows system, application servers directly communicate with Postgres to execute workflows instead of going through a central orchestrator. A client submits a workflow for execution by creating an entry for it in a Postgres workflows table. Application servers poll the table for workflows to dequeue and execute. As a server executes a workflow, it checkpoints the output of each step to Postgres. If a server executing workflows crashes or fails, another server can recover its workflows from their checkpoints.

    What you want are a locking clause (FOR UPDATE for example) to “acquire” an item from your queue and SKIP LOCKED to skip over rows that are being processed. Contrary to what you’d normally do, you’d hold a long-running transaction which maintains a lock on the row you’re processing, then on completion either commits (success) or rolls back (failure) its changes to that row.

    You also don’t want to poll. Use LISTEN instead.