Queue
Queue /
Usage
import queue from 'react-native-job-queue'
queue.configure({onQueueFinish:(executedJobs:Job[])=>{
console.log("Queue stopped and executed",executedJobs)
}});
queue.addWorker(new Worker("testWorker",async(payload)=>{
return new Promise((resolve) => {
setTimeout(() => {
console.log(payload.text);
resolve();
}, payload.delay);});
}))
queue.addJob("testWorker",{text:"Job example palyoad content text",delay:5000})
Hierarchy
- Queue
Index
Accessors
Methods
Accessors
isRunning
• get isRunning(): boolean
Defined in Queue.ts:54
Returns: boolean
true if the Queue is running and false otherwise
registeredWorkers
• get registeredWorkers(): object
Defined in Queue.ts:60
Returns: object
the workers map (readonly)
- [ key: string]: Worker‹any›
Static
instance
• get instance(): Queue
Defined in Queue.ts:43
Returns: Queue
Methods
addJob
▸ addJob<P>(workerName
: string, payload
: P
, options
: object, startQueue
: boolean): string
Defined in Queue.ts:143
adds a job to the queue
Type parameters:
▪ P: object
Parameters:
▪ workerName: string
name of the worker which should be used to excute the job
▪ payload: P
which is passed as parameter to the executer
▪Default value
options: object= { attempts: 0, timeout: 0, priority: 0 }
to set max attempts, a timeout and a priority
Name | Type | Default |
---|---|---|
attempts | number | 0 |
priority | number | 0 |
timeout | number | 0 |
▪Default value
startQueue: boolean= true
Returns: string
job id
addWorker
▸ addWorker(worker
: Worker‹any›): void
Defined in Queue.ts:115
adds a Worker to the queue which can execute Jobs
Parameters:
Name | Type | Description |
---|---|---|
worker | Worker‹any› |
Returns: void
cancelJob
▸ cancelJob(jobId
: string, exception?
: Error
): void
Defined in Queue.ts:195
cancel running job
Parameters:
Name | Type |
---|---|
jobId | string |
exception? | Error |
Returns: void
configure
▸ configure(options
: QueueOptions): void
Defined in Queue.ts:101
Parameters:
Name | Type |
---|---|
options | QueueOptions |
Returns: void
getJobs
▸ getJobs(): Promise<RawJob[]>
Defined in Queue.ts:97
Returns: Promise<RawJob[]>
a promise that resolves all jobs that are queued and not active
removeWorker
▸ removeWorker(name
: string, deleteRelatedJobs
: boolean): void
Defined in Queue.ts:128
removes worker from queue
Parameters:
Name | Type | Default |
---|---|---|
name | string | - |
deleteRelatedJobs | boolean | false |
Returns: void
start
▸ start(): Promise<void>
Defined in Queue.ts:177
starts the queue to execute queued jobs
Returns: Promise<void>
stop
▸ stop(): void
Defined in Queue.ts:188
stop the queue from executing queued jobs
Returns: void