workItems (schema/work.ts)

OpenBot · server/src/db/schema/work.ts · typescript · MIT
database, Database / ORM

Defines a durable work queue schema for distributed processing with idempotence and retry logic.

// Source: https://github.com/CopilotKit/OpenBot | License: MIT | Copyright 2026 CopilotKit
// Provided via justclaw.it.com; keep this notice with the code.
import {
  index,
  integer,
  pgTable,
  primaryKey,
  text,
  timestamp,
} from "drizzle-orm/pg-core";
import { jsonb } from "./json";

const createdAt = () =>
  timestamp("created_at", { withTimezone: true }).notNull().defaultNow();
const updatedAt = () =>
  timestamp("updated_at", { withTimezone: true }).notNull().defaultNow();

/**
 * Durable work, claimed by whichever replica gets there first, leased so a dead one's work comes
 * back.
 *
 * ONE MECHANISM, THREE FEATURES. Suspending idle computers needs it, scheduled routines need it, and
 * a hop from one Bot to another needs it. Written once with all three in view rather than t

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key