Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/hoarder-app/liteque
- Owner: hoarder-app
- Created: 2024-10-27T16:27:46.000Z (21 days ago)
- Default Branch: main
- Last Pushed: 2024-10-27T17:15:03.000Z (21 days ago)
- Last Synced: 2024-10-27T20:26:43.763Z (21 days ago)
- Topics: node, nodejs, queue, queue-workers, sqlite
- Language: TypeScript
- Homepage:
- Size: 36.1 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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
```