PostgreSQL Job Queue for Openclaw

A production-ready job queue implementation leveraging PostgreSQL for priority scheduling, batch claiming, and detailed progress tracking without external message brokers.

wpank
v1.0.0
Feb 10, 2026
1
2k
0

Install & Download

1. ClawHub CLI

The fastest way to install a skill directly from the registry.

npx clawhub@latest install postgres-job-queue

2. Manual Installation

Copy the skill folder to one of these locations

Global
~/.openclaw/skills/
Workspace
<project>/skills/

Priority: Workspace > Local > Bundled

3. Prompt Installation

Copy this prompt to OpenClaw to install it automatically.

Help me install postgres-job-queue using Clawhub. If Clawhub is not installed, install it first (npm i -g clawhub).

Prefer to download?

Get the raw skill files in a ZIP archive.

What is PostgreSQL Job Queue?

The PostgreSQL Job Queue skill provides a robust architectural pattern for managing background tasks using existing database infrastructure. By utilizing advanced SQL features like FOR UPDATE SKIP LOCKED and partial indexing, this Openclaw Skills resource allows developers to build reliable, high-concurrency task queues. This approach eliminates the operational complexity of managing external dependencies like Redis or RabbitMQ while maintaining strict data integrity and visibility into job lifecycles.

PostgreSQL Job Queue Use Cases

  • Building background task systems without the overhead of external message brokers.
  • Implementing priority-based job scheduling where critical tasks must jump the queue.
  • Tracking granular progress and multi-stage events for long-running workflows.
  • Ensuring job persistence and survival across service restarts using transactional guarantees.

How PostgreSQL Job Queue Works

  1. The schema defines a jobs table with JSONB data storage, priority levels, and worker tracking columns.
  2. Partial indexes are applied to the priority and status columns to ensure ultra-fast querying of claimable tasks.
  3. Workers use the SKIP LOCKED clause via a PL/pgSQL function to atomically claim batches of jobs without causing row-level deadlocks.
  4. The application updates job status from pending to claimed, then to running or completed, managing retries upon failure based on attempt counts.
  5. A recovery routine periodically identifies and resets stale jobs that were claimed but never completed due to worker crashes or timeouts.

PostgreSQL Job Queue Setup

  1. Initialize the PostgreSQL schema with the jobs table:
CREATE TABLE jobs (
    id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    job_type VARCHAR(50) NOT NULL,
    priority INT NOT NULL DEFAULT 100,
    status VARCHAR(20) NOT NULL DEFAULT 'pending',
    data JSONB NOT NULL DEFAULT '{}',
    progress INT DEFAULT 0,
    worker_id VARCHAR(100),
    claimed_at TIMESTAMPTZ,
    created_at TIMESTAMPTZ DEFAULT NOW(),
    attempts INT DEFAULT 0,
    max_attempts INT DEFAULT 3,
    CONSTRAINT valid_status CHECK (status IN ('pending', 'claimed', 'running', 'completed', 'failed', 'cancelled'))
);
  1. Create performance indexes:
CREATE INDEX idx_jobs_claimable ON jobs (priority DESC, created_at ASC) WHERE status = 'pending';
  1. Apply the claim_job_batch function provided in the Openclaw Skills documentation to enable safe concurrent worker access.

PostgreSQL Job Queue Data Schema & Taxonomy

The skill organizes its data within a single relational table optimized for fast state transitions. The schema follows this taxonomy:

Attribute Description
job_type Categorizes tasks so workers can subscribe to specific job classes.
priority Integer used for weighted scheduling; higher values are processed first.
status ENUM-like check constraint tracking the lifecycle from pending to completed.
data JSONB column for storing arbitrary task parameters and context.
worker_id Identifier for the specific instance currently processing the job.

PostgreSQL Job Queue Advanced Features

  • Atomic batch claiming using SKIP LOCKED to prevent worker contention and deadlocks.
  • Partial indexing strategy for O(1) job selection even in high-volume tables.
  • Automatic stale job recovery logic to handle ungraceful worker shutdowns.
  • Granular progress tracking with support for stage-specific metadata and event counting.
  • Support for multi-priority levels (Explicit, System-discovered, Backfill) to balance system load.

SKILL.md


Loading

Related Openclaw Skills

METADATA

Github Stars: 0
forks: 0

Featured*