Data layer is backward compatible with node-persistent-queue
type Payload = {
readonly name: number;
readonly email: string;
};
const storage = new Sqlite3Storage<Payload>({
path: "users.sqlite",
serialize: JSON.stringify,
deserialize: JSON.parse,
});
const queue = new Queue<Payload>({
storage,
concurrency: 3,
batchSize: 6,
handler: async (payload) => {
await saveToDb(payload);
},
});
concurrency
- number of concurrent jobs
batchSize
- number of jobs to fetch from storage at once
await queue.init();
await queue.add({ name: "User 1", email: "[email protected]" });
await queue.add({ name: "User 2", email: "[email protected]" });
await queue.add({ name: "User 3", email: "[email protected]" });