Queue servis class that we can use in offline projects.
import:
import { queueInstance } from "./app/extensions/Queue";
Workers:
Workers classes should return boolean value in resolve/rejects functions.
Example:
export default class FrameUploaderWorker {
retry: number = 5;
handle(args: any, queue: Queue): Promise<any> {
return new Promise((resolve, reject) => {
resolve(true);
});
}
before(args) {
}
after(args) {
}
}
Worker registration: (app/workers.js)
export const workers: any = {
FrameUploaderWorker
};
Parameter: Object
Return: Promise<Boolean>
Options table:
Name | Type | Description |
---|---|---|
name | string | Short name for worker |
worker | string | Worker full class name that registered |
args | any | The parameters to be used in worker |
queueInstance.add({
"name": "Create entry at remote api",
"worker": "FrameUploaderWorker",
"args": {a: 'hello' }
}).then(result => {
// do something
})
Start queue listener mechanism.
Parameter: None
Return: void
queueInstance.start();
Stop queue listener mechanism.
Parameter: None
Return: void
queueInstance.stop();
Restart queue listener mechanism after when current task is done.
Parameter: None
Return: void
queueInstance.restart();
Force the queue to restart including current task.
Parameter: None
Return: void
queueInstance.forceRestart();
Check tasks in queue listener store.
Parameter: None
Return: Promise<boolean>
Check tasks in queue listener store.
queueInstance.hasTask().then(result => {
// do something
});
Check queue avaibility.
Parameter: None
Return: Boolean
queueInstance.isActive();