import { Worker } from "https://deno.land/x/kvmq@v0.3.0/mod.ts";
Represents a worker that processes jobs from a queue.
Remember to call processJobs to start processing jobs.
Constructors
Properties
Set of promises for finishing jobs that are currently being processed.
When jobs are finished, they remove themselves from this set.
To check the number of currently running jobs, use worker.activeJobs.size()
.
To wait for all currently running jobs to finish, use await Promise.all(worker.activeJobs)
.
Kv database to use for accessing the queue.
The function that processes the jobs.
Key prefix to use for accessing queue's data.
Worker options.
Promise for finishing currently running processors.
This promise gets replaced with a new one every time processJobs is called. If you call and forget processJobs, you can use this to get the promise again and await it.
This doesn't include the jobs that already started processing. To wait for them too use activeJobs.
Methods
See WorkerEventMap for available events.
Starts processing jobs.
If you already called this method and it's still running, the current call will first wait for previous one to finish.
Pass an abort signal to stop processing jobs at a later time.
Aborting won't wait for the already started jobs to finish processing.
To also wait for all currently running jobs, use await Promise.all(worker.activeJobs)
.
Returns a promise that resolves when the job popping loop exits.
The only ways to exit this loop is to use the signal argument or stopProcessing.
It can reject when getting or updating jobs in the database fails.
Whenever an error occurs in the processing handler, the worker will emit an error
event.
Aborts all currently running processors.
This is an alternative to passing an abort signal to processJobs.