-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
readme: Add more details in the readme
- Loading branch information
1 parent
210460d
commit b40389a
Showing
1 changed file
with
77 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,80 @@ | ||
<div align="center"> | ||
<a href="https://github.com/hoarder-app/liteque/actions/workflows/ci.yml"> | ||
<img alt="GitHub Actions Workflow Status" src="https://img.shields.io/github/actions/workflow/status/hoarder-app/liteque/ci.yml" /> | ||
</a> | ||
<a href="https://github.com/hoarder-app/liteque/releases"> | ||
<img alt="GitHub Release" src="https://img.shields.io/github/v/release/hoarder-app/liteque" /> | ||
</a> | ||
</div> | ||
|
||
# Liteque | ||
|
||
Liteque is a sqlite-based job queue for Node.js. | ||
A simple typesafe sqlite-based job queue for Node.js. | ||
|
||
## Installation | ||
|
||
```bash | ||
$ npm install liteque | ||
``` | ||
|
||
## Usage | ||
|
||
```ts | ||
import { buildDBClient, SqliteQueue } from "liteque"; | ||
import { z } from "zod"; | ||
|
||
const db = buildDBClient(":memory:", true); | ||
|
||
const requestSchema = z.object({ | ||
message: z.string(), | ||
}); | ||
const ZRequest = z.infer<typeof requestSchema>; | ||
|
||
// Init the queue | ||
const queue = new SqliteQueue<ZRequest>("requests", db, { | ||
defaultJobArgs: { | ||
numRetries: 2, | ||
}, | ||
}); | ||
|
||
// Enqueue a job | ||
await queue.enqueue({ | ||
message: "Hello world", | ||
}); | ||
|
||
// Start the runner | ||
const worker = new Runner<ZRequest>( | ||
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 | ||
TODO | ||
$ pnpm typecheck | ||
$ pnpm test | ||
``` |