const { Producer } = require('orkid');
- 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
.
// 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 byJSON.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
, callingproducer.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, callingproducer.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.
const { Consumer } = require('orkid');