Guides
Configuring Queues

Configuring Queues

When specifying a queue, you can optionally pass an options object to customize the queue's behavior. There's currently 1 option you can customize:

  1. maxAttempts - Default is 1. Increasing this means your job will be retried until currentAttempt <= maxAttempts.

maxAttempts

By increasing the maxAttempts for a job, you are allowing the job to be retried in the future. All jobs have a default maxAttempts of 1, so if you want a job to run at most 5 times before being marked as failed, you can set maxAttempts to 5.

ts
import { Sidetrack } from "sidetrack";
 
const sidetrack = new Sidetrack<{
userOnboarding: { email: string };
}>({
databaseOptions: {
connectionString: process.env["DATABASE_URL"]!,
},
queues: {
userOnboarding: {
handler: async (job) => {
throw new Error("intentionally failing job");
},
options: {
maxAttempts: 5,
(property) maxAttempts?: number | undefined
},
},
},
});
 
sidetrack.start();
 
sidetrack.insertJob("userOnboarding", { email: "a@example.com" });
ts
import { Sidetrack } from "sidetrack";
 
const sidetrack = new Sidetrack<{
userOnboarding: { email: string };
}>({
databaseOptions: {
connectionString: process.env["DATABASE_URL"]!,
},
queues: {
userOnboarding: {
handler: async (job) => {
throw new Error("intentionally failing job");
},
options: {
maxAttempts: 5,
(property) maxAttempts?: number | undefined
},
},
},
});
 
sidetrack.start();
 
sidetrack.insertJob("userOnboarding", { email: "a@example.com" });

This job will fail on the first run then move to retrying status since its currentAttempt (1) is less than 5. After 5 attempts, the job will transition to a status of failed.