Reliable scheduling with trigger.dev

trigger.dev is an open source background job platform. With trigger.dev you can easily create, schedule, and manage background jobs using code.

Read on to learn how to create complex, reliable scheduling with trigger.dev.

Before you start

Before you start, ensure:

Create your first trigger task

The tinybird-trigger repo contains some examples for trigger.dev that show you how to execute Tinybird Copy Pipes and use the Query API to get data from tasks.

  1. Create a working directory, and run npx trigger.dev@latest init to connect the project to trigger.dev.

  2. Inside the trigger directory, add the copy.ts file from the tinybird-trigger repo.

  3. Create a new file called myTask.ts and add the following code:

import { task } from "@trigger.dev/sdk/v3";
import { tinybirdCopyTask } from "./copy";

export const exampleExecutor = task({
    id: "example-executor",
    run: async (payload, { ctx }) => {
        console.log("Example executor task is running");

        // Run a copy job
        const copyResult = await tinybirdCopyTask.triggerAndWait({ pipeId: <COPY_PIPE_ID> });
        console.log(copyResult);

    },
});
  1. Go to your Tinybird Workspace, and create a new Pipe. Use the following SQL:
SELECT number + 1 AS value
FROM numbers(100)
  1. Name the Pipe my_copy, then select Create Copy from the actions menu. Follow the prompts to create the Copy Pipe.

  2. Update myTask.ts, replacing <COPY_PIPE_ID> with the name of your Pipe, my_copy in this case.

  3. Create a .env file in your directory root.

  4. Go to your Tinybird Workspace and copy the Admin Token, then add it to the .env file as follows:

TINYBIRD_TOKEN=p.eyJ...
  1. Run npx trigger.dev@latest dev to push the task to trigger.dev.

  2. Go to your trigger.dev dashboard, and perform a test run to trigger the task and the Copy Pipe.

  3. Go to your Tinybird Workspace and check the Copy Pipe results.

See also

Updated