You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We should give users the ability to hook into the task and run lifecycle
import{prisma}from"./db";import{prisma}from"./db";import{TriggerClient}from"@trigger.dev/sdk";constclient=newTriggerClient({id: "my-app",hooks: {onTaskCompleted: (task,job,payload,ctx)=>prisma.tasks.upsert({where: {id: task.idempotencyKey},create: {id: task.idempotencyKey,data: task.output},update: {data: task.output},}),// keep a local record of all tasks if you want tobeforeTaskRun: async(task,job,payload,ctx)=>{constexistingTask=awaitprisma.tasks.findUnique({id: task.idempotencyKey,});returnexistingTask?.data;// Can keep a local cache of tasks and provide output},onTaskFailed: async(task,error,job,payload,ctx)=>{// Do something when a task fails},onRunFinished: async(job,run,payload,ctx)=>{// Do something when a run is completed/cancelled/failed},onRunCompleted: async(job,run,payload,ctx)=>{// Do something when a run is completed},onRunCancelled: async(job,run,payload,ctx)=>{// Do something when a run is cancelled},onRunFailed: async(job,run,payload,ctx)=>{// Do something when a run is cancelled},},});// They can also be defined on at the job levelclient.defineJob({id: "my-job",onTaskCompleted: (task,payload,ctx)=>{},beforeTaskRun: async(task,payload,ctx)=>{},onTaskFailed: async(task,error,payload,ctx)=>{// Do something when a task fails},onRunFinished: async(run,payload,ctx)=>{// Do something when a run is completed/cancelled/failed},onRunCompleted: async(run,payload,ctx)=>{// Do something when a run is completed},onRunCancelled: async(run,payload,ctx)=>{// Do something when a run is cancelled},onRunFailed: async(run,payload,ctx)=>{// Do something when a run is cancelled},});
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
We should give users the ability to hook into the task and run lifecycle
Beta Was this translation helpful? Give feedback.
All reactions