Bulk Operations

When you have several jobs you need to schedule at once, it makes sense to do them in batches. Taskless has a Bulk Operation API accessible under <your-queue>.bulk.* on every integration as well as the core Taskless Client. The Taskless service allows you to send up to 100 calls in a single request; the Client will take care of splitting your request up into the maximum allowed chunk size.

The Bulk Response

Because Bulk Operations may need to make multiple requests, a response will be a promise containing a tuple of [successes, errors] returned from the bulk calls. If no errors are encountered, then index [1] of the tuple will be undefined.

1// <T> is the type specified when you made your Queue
2type BulkOperationResult<T> = [Job<T>[], Error[] | undefined];

Bulk Enqueue

Allows for enquing multiple jobs at the same time. Because JobOptions can differ per job, they must be specified with each individual job entry.

1const [jobs, errors] = await myQueue.bulk.enqueue([
2 {
3 name: "job-identifier",
4 payload: T,
5 jobOptions: JobOptions ?? undefined,
6 }, // ...
7]);

Using bulk.enqueue for a Fan-Out Operation

1// schedule a jobs in bulk with the same job options
2// names use the index value of the map() operation
3const [jobs, errors] = await myQueue.bulk.enqueue(
4 myPayloads.map((p, idx) => {
5 return {
6 name: `fanout-sample-${idx}`,
7 payload: p,
8 jobOptions: {
9 retries: 3,
10 },
11 };
12 })
13);

Using bulk.enqueue for Bulk Scheduling

1// schedule jobs in bulk, using a value in the payload
2// to set the Job Identifier
3const [jobs, errors] = await myQueue.bulk.enqueue(myPayloads.map((p) => {
4 return {
5 name: ["sendTo", p.targetUserId].
6 payload: p
7 }
8}))

Bulk Cancel

Similar to cancelJob, but operates in bulk on an array of Job Identifiers.

1const [jobs, errors] = await myQueue.bulk.cancel([jobIdentifiers]);