
Trigger.dev Has a Free API That Makes Background Jobs in TypeScript Actually Reliable
Trigger.dev is the open-source background job framework for TypeScript. Define tasks with full type safety, automatic retries, and built-in observability. Define a Task import { task } from " @trigger.dev/sdk/v3 " ; export const scrapeProduct = task ({ id : " scrape-product " , retry : { maxAttempts : 3 , factor : 2 , minTimeoutInMs : 1000 }, run : async ( payload : { url : string ; category : string }) => { const html = await fetch ( payload . url ). then ( r => r . text ()); const product = parseProduct ( html ); await db . product . create ({ data : { ... product , category : payload . category , url : payload . url }, }); return { title : product . title , price : product . price }; }, }); Trigger From Anywhere import { scrapeProduct } from " ./trigger/scrape " ; // From API route app . post ( " /api/scrape " , async ( req , res ) => { const handle = await scrapeProduct . trigger ({ url : req . body . url , category : req . body . category , }); res . json ({ jobId : handle . id })
Continue reading on Dev.to JavaScript
Opens in a new tab



