Skip to content

Latest commit

History

History
126 lines (80 loc) 路 2.75 KB

API.md

File metadata and controls

126 lines (80 loc) 路 2.75 KB

API Documentation

Table of Contents


Producer

const { Producer } = require('orkid');

Creating a producer for a queue

  • Many producers can send jobs to a single queue.
  • For more queues, create separate instances of producers with separate qname.

Producers can be used after instantiating Producer class.

const producer = new Producer(qname, [options]);

Parameters:

qname:

  • Queue name.
  • String.
  • Required.

options:

  • Producer options.
  • Object.
  • Optional.
`options`: {
  `redisOptions`:

    - Object.
    - Any valid `ioredis` options.
    - Optional.
}

If options is omitted or redisOptions are not present, ioredis defaults will be used, as described here: https://github.com/luin/ioredis/blob/master/API.md#new_Redis_new

Return value:

Returns an instance of Producer.


Adding tasks to queue with or without de-duplication

// producer is a `Producer` instance
await producer.addTask(data, [dedupKey]);

Parameters:

data

  • Object, string or any type that can be passed through JSON.stringify(). Will be parsed again by JSON.parse() before passing to the worker function of the consumer.
  • null will be used if absent.

dedupKey

  • String.
  • Optional.
  • Use if you need task de-duplication.
  • If a still unprocessed/pending tasks are present in the queue with the same dedupKey, calling producer.addTask() WILL NOT add the task again.
  • Notice the still unprocessed/pending qualifier for de-duplication. If there were tasks previously in the queue with the same dedupKey but have been processed already, calling producer.addTask() will add the tasks as usually. De-duplication only happens in pending tasks level. Tasks that are waiting to be retried after failure are considered pending too.

Return value:

Returns Promise <string | null>

  • If the task WAS NOT added due to de-duplication: Promise<null>
  • If the task was added: Promise<string>. String can be any auto-generated ID.

Consumer

const { Consumer } = require('orkid');

Creating consumers for a queue


The Worker Function


Starting consumers


Pausing/resuming consumers


Notes on consumer concurrency


Notes on task order