This guide will show you how to trigger tasks from database changes using Sequin
In this guide, you’ll learn how to use Sequin to trigger Trigger.dev tasks from database changes.
posts table and then send the payload of the post to an API endpoint that will call tasks.trigger() to create the embedding and update the database.
As long as you create an HTTP endpoint that Sequin can deliver webhooks to, you can use any web framework or edge function (e.g. Supabase Edge Functions, Vercel Functions, Cloudflare Workers, etc.) to invoke your Trigger.dev task. In this guide, we’ll show you how to setup Trigger.dev tasks using Next.js API Routes.
You’ll need the following to follow this guide:
posts table.src/trigger/tasks directory, create a new file called create-embedding-for-post.ts and add the following code:post_embeddings table.create-embedding-for-post task to your Trigger.dev cloud project by running the following command:create-embedding-for-post task:
create-embedding-for-post task.
route.ts file in a /app/api/create-embedding-for-post directory:create-embedding-for-post task..env.local file:SEQUIN_WEBHOOK_SECRET ensures that only Sequin can access your API endpoint.The TRIGGER_SECRET_KEY is used to authenticate requests to Trigger.dev and can be found in the API keys tab of the Trigger.dev dashboard.The OPENAI_API_KEY and DATABASE_URL are used to create an embedding using OpenAI and connect to your database. Be sure to add these as environment variables in Trigger.dev as well.posts table to your Trigger.dev task.
local_endpoint) and flip the Use localhost switch. Follow the instructions in the Sequin console to install the Sequin CLI, then run:Authorization and the value to Bearer SEQUIN_WEBHOOK_SECRET.posts table (i.e public.posts).updated_at and start at the beginning of the table. We won’t apply any filters:
posts_push_consumer) and in the HTTP Endpoint section select the local_endpoint you created above. Add the exact API route you created in the previous step (i.e. /api/create-embedding-for-post):
npm run devnpx trigger.dev@latest devsequin tunnel --ports=3001:local_endpoint
200 response in your Next.js app:
create-embedding-for-post task.