feat: add application productivity foundations
Quality / quality (ubuntu-latest) (push) Failing after 22s
Quality / quality (windows-latest) (push) Canceled after 0s

This commit is contained in:
2026-08-23 11:13:03 +05:30
parent 46195462c3
commit 64ab20cc95
42 changed files with 1533 additions and 40 deletions
+34 -17
View File
@@ -2,6 +2,7 @@ import { getDb, hasDb, registerDb, type Db } from "@wrnexus/db";
import { connectFromConfig } from "@wrnexus/db/connect";
import { memoryQueueStore, type QueueStore } from "./durable.ts";
import { installSqliteQueueSchema, sqliteQueueStore } from "./sqlite.ts";
import { databaseQueueStore, installDatabaseQueueSchema } from "./database.ts";
export type QueueStorage = "sqlite" | "database" | "memory";
@@ -29,21 +30,39 @@ function lazyStore(resolve: () => Promise<QueueStore>): QueueStore {
let pending: Promise<QueueStore> | undefined;
const ready = () => (pending ??= resolve());
return {
async put(job) { return (await ready()).put(job); },
async get(id) { return (await ready()).get(id); },
async remove(id) { return (await ready()).remove(id); },
async due(now, limit) { return (await ready()).due(now, limit); },
async list(name) { return (await ready()).list(name); },
async put(job) {
return (await ready()).put(job);
},
async get(id) {
return (await ready()).get(id);
},
async remove(id) {
return (await ready()).remove(id);
},
async due(now, limit) {
return (await ready()).due(now, limit);
},
async list(name) {
return (await ready()).list(name);
},
async findByIdempotencyKey(name, key) {
return (await ready()).findByIdempotencyKey?.(name, key) ?? null;
},
async size() { return (await ready()).size?.() ?? (await (await ready()).list()).length; },
async size() {
return (await ready()).size?.() ?? (await (await ready()).list()).length;
},
async claim(id, worker, leaseUntil, now) {
return (await ready()).claim?.(id, worker, leaseUntil, now) ?? true;
},
async release(id, worker) { await (await ready()).release?.(id, worker); },
async archive(record) { await (await ready()).archive?.(record); },
async history(id) { return (await ready()).history?.(id) ?? []; },
async release(id, worker) {
await (await ready()).release?.(id, worker);
},
async archive(record) {
await (await ready()).archive?.(record);
},
async history(id) {
return (await ready()).history?.(id) ?? [];
},
};
}
@@ -72,15 +91,13 @@ async function resolveConfiguredStore(): Promise<QueueStore> {
}
}
if (db.driver.dialect !== "sqlite") {
throw new Error(
`WRN-QUEUE-DATABASE: configured queue storage currently requires SQLite; ` +
`database '${databaseName}' uses ${db.driver.dialect}. Pass a custom queue store for that driver.`,
);
}
const table = config.table ?? "wrnexus_jobs";
await installSqliteQueueSchema(db, table);
return sqliteQueueStore(db, table);
if (db.driver.dialect === "sqlite") {
await installSqliteQueueSchema(db, table);
return sqliteQueueStore(db, table);
}
await installDatabaseQueueSchema(db, table);
return databaseQueueStore(db, table);
}
/** Lazy global store used by defineQueue; runtime config is read on first operation. */