Skip to content

phaux/kvmq

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

KVMQ

deno doc

Library inspired by BullMQ for Deno.

  • Built for Deno.
  • Uses Deno's KV storage.

Example

import { Queue } from "https://deno.land/x/kvmq/mod.ts";

const db = await Deno.openKv();

const queue = new Queue<{ name: string }>(db, "test");

await queue.pushJob({ name: "Alice" });
await queue.pushJob({ name: "Bob" }, { priority: 1 });
await queue.pushJob({ name: "Kazik" }, { retryCount: 1 });
await queue.pushJob({ name: "Zenek" }, { repeatCount: 1 });

const worker = queue.createWorker(async (job) => {
  await new Promise((resolve) => setTimeout(resolve, 1000));
  console.log(`Hello ${job.state.name}!`);
});

worker.addEventListener("error", (ev) => {
  console.error(
    `Error ${ev.detail.error.message} while processing ${ev.detail.job.state.name}`,
  );
});

const controller = new AbortController();
await worker.processJobs({ signal: controller.signal });

See more examples in tests.

TODO

  • Use Deno's KV queue instead of polling.
  • More tests

About

Library inspired by BullMQ for Deno

Resources

Stars

Watchers

Forks

Packages

No packages published