-
Notifications
You must be signed in to change notification settings - Fork 5
References
All methods will explain in this section with examples.
Create new task and return it's queue id.
| Name | Type | Description |
|---|---|---|
| handler | string | Worker class name. |
| args | string | Worker parameters. |
| priority | string | Queue priority value. Default: 0
|
| tag | string | Task idenitity tag. |
| unique | boolean | Only single task in storage by tagging until done. |
Parameter: Object
Return: Promise<boolean | string>
Example:
const queue = new Queue();
const channel = queue.create("channel-name");
channel.add({
handler: "SendEmail",
tag: "email-sender",
args: { email: "johndoe@example.com", fullname: "John Doe" },
priority: 2,
}).then(result => {})Start the queue listener. If has any tasks waiting the run, starts the process of these tasks. Next when adding tasks will run automaticly.
Parameter: None
Return: Promise<Boolean>
Example:
const queue = new Queue();
const channel = queue.create("channel-name");
channel.start().then(status => console.log(status));Stop the queue listener after current tasks is done.
Parameter: None
Return: Void
channel.stop();Stop the queue listener including current task.
Parameter: None
Return: Void
channel.forceStop();Create a new channel.
Parameter: String
Return: Channel class instance
const channel = qeueu.create("channel-a");
channel.add({
handler: "SendEmail",
args: { email: "johndoe@example.com", fullname: "John Doe" },
}).then(result => {})Checks the channel repository has any task.
Parameter: None
Return: Promise<Boolean>
channel.isEmpty().then(status => console.log(status));Get the number of tasks.
Parameter: None
Return: Promise<Number>
channel.count().then(count => console.log(count));Get the number of tasks by a specific tag.
Parameter: None
Return: Promise<Number>
channel.countByTag("send-email").then(count => console.log(count));Clear all tasks.
Parameter: None
Return: Promise<Void>
channel.clear().then(() => );Clear all tasks by a specific tag.
Parameter: String
Return: Promise<Void>
channel.clearByTag("send-email").then(() => )Checks a task by queue id.
Parameter: String
Return: Promise<Boolean>
channel
.add({
handler: "SendEmail",
args: { email: "johndoe@example.com", fullname: "John Doe" },
})
.then(id => {
channel.has(id).then(result => console.log(result));
});Checks a task by tag.
Parameter: String
Return: Promise<Boolean>
channel.hasByTag("email-sender").then(result => console.log(result));