Quickstart

Quickstart

In this tutorial, you'll learn how to add Sidetrack to your project and run your first job.

  1. Install using your package manager of choice.
bash
npm install sidetrack
bash
npm install sidetrack
  1. Import it into your project, and initialize Sidetrack by defining your queues.
⚠️

Please note that we only support PostgreSQL at the moment.

ts
import { Sidetrack } from "sidetrack";
 
const sidetrack = new Sidetrack<{
userOnboarding: { email: string }
}>({
databaseOptions: {
connectionString: process.env["DATABASE_URL"]!
},
queues: {
userOnboarding: {
handler: async (job) => {
console.log(`Welcome ${job.payload.email}!`)
},
},
},
});
 
sidetrack.start(); // starts listening for new jobs in your DB
ts
import { Sidetrack } from "sidetrack";
 
const sidetrack = new Sidetrack<{
userOnboarding: { email: string }
}>({
databaseOptions: {
connectionString: process.env["DATABASE_URL"]!
},
queues: {
userOnboarding: {
handler: async (job) => {
console.log(`Welcome ${job.payload.email}!`)
},
},
},
});
 
sidetrack.start(); // starts listening for new jobs in your DB

Notice how you pass in the types for your queues, specifying your queueName as the key (userOnboarding), and the value being the type for your job's payload ({email: string}).

To insert a job, use the insertJob function to specify the queue and the job payload.

ts
sidetrack.insertJob("userOnboarding", { email: "a@example.com" });
ts
sidetrack.insertJob("userOnboarding", { email: "a@example.com" });

Once the job is inserted, Sidetrack will pick it up and run it. You should see a log in your terminal!

Welcome a@example.com!
Welcome a@example.com!

You are ready to continue your Sidetrack journey! Good luck (and don't get sidetracked)!