Skip to content
This repository was archived by the owner on May 3, 2024. It is now read-only.

References

Ahmet edited this page May 3, 2018 · 5 revisions

All methods will explain in this section with examples.

add()

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()

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()

Stop the queue listener after current tasks is done.

Parameter: None

Return: Void

channel.stop();

forceStop()

Stop the queue listener including current task.

Parameter: None

Return: Void

channel.forceStop();

create()

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 => {})

isEmpty()

Checks the channel repository has any task.

Parameter: None

Return: Promise<Boolean>

channel.isEmpty().then(status => console.log(status));

count()

Get the number of tasks.

Parameter: None

Return: Promise<Number>

channel.count().then(count => console.log(count));

countByTag()

Get the number of tasks by a specific tag.

Parameter: None

Return: Promise<Number>

channel.countByTag("send-email").then(count => console.log(count));

clear()

Clear all tasks.

Parameter: None

Return: Promise<Void>

channel.clear().then(() => );

clearByTag()

Clear all tasks by a specific tag.

Parameter: String

Return: Promise<Void>

channel.clearByTag("send-email").then(() => )

has()

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));
  });

hasByTag()

Checks a task by tag.

Parameter: String

Return: Promise<Boolean>

channel.hasByTag("email-sender").then(result => console.log(result));

Clone this wiki locally