DEV Community

Alex Spinov
Alex Spinov

Posted on

Trigger.dev Has a Free Background Jobs Framework — Here's How to Use It

Cron jobs on your server crash when it restarts. AWS Lambda has cold starts. Trigger.dev gives you reliable background jobs with retries, schedules, and a beautiful dashboard — in TypeScript.

What Is Trigger.dev?

Trigger.dev is an open-source background jobs framework. Define jobs in TypeScript, trigger them via API or schedule, and monitor everything in a dashboard.

Quick Start

npx trigger.dev@latest init
Enter fullscreen mode Exit fullscreen mode
// src/trigger/hello-world.ts
import { task } from "@trigger.dev/sdk/v3";

export const helloWorld = task({
  id: "hello-world",
  run: async (payload: { name: string }) => {
    console.log(`Hello, ${payload.name}!`);

    // Long-running work — won't timeout
    await heavyProcessing(payload);

    return { success: true };
  },
});
Enter fullscreen mode Exit fullscreen mode

Trigger From Your API

import { helloWorld } from "./trigger/hello-world";

// From any API route
app.post('/process', async (req, res) => {
  const handle = await helloWorld.trigger({ name: "World" });
  res.json({ jobId: handle.id });
});
Enter fullscreen mode Exit fullscreen mode

Key Features

Retries with Backoff

export const resilientTask = task({
  id: "resilient-task",
  retry: {
    maxAttempts: 5,
    factor: 2,
    minTimeoutInMs: 1000,
    maxTimeoutInMs: 30000,
  },
  run: async (payload) => {
    await callExternalAPI(payload);
  },
});
Enter fullscreen mode Exit fullscreen mode

Scheduled Tasks (Cron)

import { schedules } from "@trigger.dev/sdk/v3";

export const dailyReport = schedules.task({
  id: "daily-report",
  cron: "0 9 * * *", // Every day at 9 AM
  run: async () => {
    const data = await gatherMetrics();
    await sendReport(data);
  },
});
Enter fullscreen mode Exit fullscreen mode

Long-Running Tasks (up to 5 hours)

export const videoProcessing = task({
  id: "process-video",
  machine: { preset: "large-2x" },
  run: async (payload: { videoUrl: string }) => {
    // Can run for hours — no timeouts
    await downloadVideo(payload.videoUrl);
    await transcodeVideo();
    await uploadResult();
  },
});
Enter fullscreen mode Exit fullscreen mode

Why Trigger.dev

Feature Trigger.dev BullMQ AWS Lambda
Duration limit 5 hours Unlimited 15 min
Dashboard Beautiful Bull Board CloudWatch
TypeScript Native Yes Yes
Retries Built-in Built-in Built-in
Scheduling Built-in Built-in EventBridge
Self-hosted Yes Yes No
No Redis needed Yes No (requires Redis) N/A

Get Started


Running background scraping jobs? My Apify actors handle scheduled data extraction. Custom solutions: spinov001@gmail.com

Top comments (0)