Trigger.dev lets you run long-running background jobs in TypeScript with automatic retries, scheduling, and observability. No infrastructure to manage.
Define a Job
import { task } from '@trigger.dev/sdk/v3';
export const processVideo = task({
id: 'process-video',
retry: { maxAttempts: 3 },
run: async (payload: { videoUrl: string; userId: string }) => {
// Step 1: Download
const video = await downloadVideo(payload.videoUrl);
// Step 2: Transcode (can take minutes)
const transcoded = await transcodeVideo(video, '1080p');
// Step 3: Upload to S3
const url = await uploadToS3(transcoded);
// Step 4: Notify user
await sendNotification(payload.userId, `Video ready: ${url}`);
return { url };
}
});
Trigger from Your App
import { tasks } from '@trigger.dev/sdk/v3';
// From an API endpoint
app.post('/api/upload-video', async (req, res) => {
const handle = await tasks.trigger('process-video', {
videoUrl: req.body.url,
userId: req.user.id
});
res.json({ jobId: handle.id });
});
// Scheduled (cron)
export const dailyReport = task({
id: 'daily-report',
run: async () => {
const data = await generateReport();
await sendEmail('team@company.com', data);
}
});
Wait for External Events
export const onboardUser = task({
id: 'onboard-user',
run: async (payload: { userId: string }) => {
await sendWelcomeEmail(payload.userId);
// Wait up to 24h for email verification
const verified = await wait.for({ seconds: 86400 });
if (verified) {
await activateAccount(payload.userId);
} else {
await sendReminder(payload.userId);
}
}
});
Why This Matters
- TypeScript native: Write jobs in the same language as your app
- Automatic retries: With exponential backoff
- Real-time logs: See exactly what your job is doing
- No infrastructure: Managed execution environment
Need custom background job systems or workflow automation? I build developer tools. Check out my web scraping actors on Apify or reach out at spinov001@gmail.com for custom solutions.
Top comments (0)