Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/hoarder-app/liteque

A SQLite based job queue implementation in typescript
https://github.com/hoarder-app/liteque

node nodejs queue queue-workers sqlite

Last synced: 19 days ago
JSON representation

A SQLite based job queue implementation in typescript

Awesome Lists containing this project

README

        

# Liteque

![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/hoarder-app/liteque/ci.yml) ![NPM Version](https://img.shields.io/npm/v/liteque)

A simple typesafe sqlite-based job queue for Node.js.

## Installation

```bash
$ npm install liteque
```

## Usage

```ts
import { buildDBClient, Runner, SqliteQueue } from "liteque";
import { z } from "zod";

const db = buildDBClient(":memory:", true);

const requestSchema = z.object({
message: z.string(),
});
const ZRequest = z.infer;

// Init the queue
const queue = new SqliteQueue("requests", db, {
defaultJobArgs: {
numRetries: 2,
},
});

// Enqueue a job
await queue.enqueue({
message: "Hello world",
});

// Start the runner
const worker = new Runner(
queue,
{
run: async (job) => {
logger.info(`[${job.id}] ${job.data.message}`);
},
onComplete: async (job) => {
console.log(`[${job.id}] Completed successfully`);
},
onError: async (job) => {
logger.error(
`[${job.id}] job failed: ${job.error}\n${job.error.stack}`,
);
},
},
{
concurrency: 1,
pollIntervalMs: 1000,
timeoutSecs: 60,
validator: requestSchema,
},
);

```

## Development

```base
$ pnpm install

# And before submitting a PR

$ pnpm typecheck
$ pnpm test
```