校对:soup
Postgres 存储适配器 @absolutejs/queue在Drizzle上兴建的 这个
生产 JobStore:耐用,原子多工者通过
FOR UPDATE SKIP LOCKED双方的船舶便利工厂 postgres.js
和 Neon 的 WebSocket 驱动程序(@neondatabase/serverless(b) 基础
buildPostgresJobStore 接受任何 Drizzle Postgres 数据库,所以其他
驱动程序(包括 Bun SQL 和 node-postgres工作也一样。 它的便携式JSONB
编码保存所有支持驱动器的有效载荷物体.
安装
# pick your driver
bun add @absolutejs/queue @absolutejs/queue-postgres drizzle-orm postgres
# …or
bun add @absolutejs/queue @absolutejs/queue-postgres drizzle-orm @neondatabase/serverless
postgres 财务报告和审定财务报表 @neondatabase/serverless 为: 选项 相位分解 -
安装任何您要使用的.
用法为 postgres.js
import { createPostgresJobStore } from '@absolutejs/queue-postgres/postgres';
import { createJobRegistry, defineJobs, queue, t } from '@absolutejs/queue';
import postgres from 'postgres';
const jobs = defineJobs({
'email.send': t.Object({ to: t.String(), subject: t.String() })
});
const registry = createJobRegistry(jobs).on(
'email.send',
async ({ to, subject }) => {}
);
// Share your app's existing postgres.js client (one pool)…
const client = postgres(process.env.DATABASE_URL, { prepare: false });
const store = createPostgresJobStore({ client, jobs });
// …or let the adapter open its own connection:
// const store = createPostgresJobStore({ connectionString: url, jobs });
app.use(queue({ registry, store }));
与尼永使用( L)@neondatabase/serverless(中文(简体) )
createNeonJobStore 镜像 createPostgresJobStore 但用的是尼永号
WebSocket Pool. (原始内容存档于2017-09-29). 重要: 队列 claimDue 打开交易
选择 FOR UPDATE SKIP LOCKED. Neon 的 HTTP 驱动程序
(单位:千美元)drizzle-orm/neon-http)是单词,不能进行行级
锁 – 在此使用 WebSocket Pool 驱动程序. 您的应用程序的另一个代码可以
继续使用 HTTP 驱动程序; 它们是独立的 .
import {
createNeonJobStore,
neonConfig
} from '@absolutejs/queue-postgres/neon';
import { createJobRegistry, defineJobs, queue, t } from '@absolutejs/queue';
import { Pool } from '@neondatabase/serverless';
// Bun ships a global WebSocket; for node, polyfill once:
// import ws from 'ws'; neonConfig.webSocketConstructor = ws;
const jobs = defineJobs({
'email.send': t.Object({ to: t.String(), subject: t.String() })
});
// Share an existing Neon Pool…
const pool = new Pool({ connectionString: process.env.DATABASE_URL });
const store = createNeonJobStore({ jobs, pool });
// …or let the adapter open its own:
// const store = createNeonJobStore({ connectionString: url, jobs });
使用任何其他 Drizzle Postgres 适配器
两家工厂都是薄薄的包裹 buildPostgresJobStore(db, jobs), (中文(简体) ),
接受任何 PgDatabase<any, any, any> 从Drizzle。 如果您使用
drizzle-orm/node-postgres,构建 db 自己传过来:
import { buildPostgresJobStore, queueSchema } from '@absolutejs/queue-postgres/drizzle';
import { drizzle } from 'drizzle-orm/node-postgres';
import { Pool } from 'pg';
const pool = new Pool({ connectionString: process.env.DATABASE_URL });
const db = drizzle(pool, { schema: queueSchema });
const store = buildPostgresJobStore(db, jobs);
移徙
在您的 Drizzle 计划中加入表格, 因此它包含在迁移中 :
export { queueJobsTable } from '@absolutejs/queue-postgres/drizzle';
礛 drizzle-kit generate 编号 : push 和往常一样.
如何要求工作
claimDue 在交易内运行 :
SELECT … FROM queue_jobs
WHERE status = 'pending' AND run_at <= $now
ORDER BY run_at LIMIT $n
FOR UPDATE SKIP LOCKED; -- concurrent workers skip locked rows
-- then UPDATE those ids → status='claimed'
这保证了将一份工作交给一名工人,即使进行了许多工人投票.
倒闭工人由 reapStuck (租赁期满) pending) (中文(简体) ).
许可证
阿帕奇-2.0 — 见 自由主义。 。 。 .
原子能围栏
适配器现在指定 claim_token 与每项索赔和执行
completeClaim 编号 : failClaim 作为工作标识、符号和
status = 'claimed'。过期、被取消或被取代的尝试返回 false
不改变当前工作。 更新队列工人使用此能力
自动; requireClaimFencing: true 拒绝不兼容的商店.
应用此添加剂迁移 在此之前 启动更新的适配器(或生成)
从导出 queueJobsTable 使用您的应用程序的迁移工具 :
ALTER TABLE queue_jobs ADD COLUMN IF NOT EXISTS claim_token text;
推出期间排水老工人. 年长的二进制仍然没有栅栏 更新且无法提供此保证。 索赔围栏保护队列行; 处理器必须分别编写栅栏应用程序和外部副作用.
租期到期意味着一次尝试。 将耗尽的工作移到 dead
租期错误,所以工人的再生死亡无法避免 maxAttempts。 。 。 .
这个 /drizzle 切入点 (0.1.8+) 不装入可选的 postgres 或神经连接工厂。 与 Bun SQL 或已存在的 Drizzle 连接使用,包括 schema 生成. 现有的根出口仍然相容.
混合工人版本
用队列0.8.4,启用 requireKindFiltering: true 关于工人。 索赔为
仅限于适配器的工作定义和工人登记
在数据库应用其索赔限额之前,处理者。 空处理器索赔
没什么 在生产新产品之前,将每个工人升级到一个共享的表格上
工作类型;年长、没有过滤的工人仍然可以要求和拒绝这些工作.