client.defineJob({ id:"alert-on-new-github-issues", name:"Alert on new GitHub issues", version:"1.0.0", trigger: github.triggers.repo({ event: events.onIssueOpened, owner:"triggerdotdev", repo:"trigger.dev",}),run:async(payload, io, ctx)=>{const record =await io.runTask("sync-github-issue",async(task)=>{return prisma.githubIssues.create({ data:{number: payload.issue.number, title: payload.issue.title, body: payload.issue.body, url: payload.issue.html_url, repo: payload.repository.full_name, owner: payload.repository.owner.login,},});},//this is optional{ name:"Sync GitHub Issue", icon:"github"});},});
A Task is a cached unit of work in a Job Run that are logged to the Trigger.dev UI. You can use io.runTask() to create and run a Task inside a Run.
Any interaction with an external service (database or API) should be wrapped in a Task. Failing to
do so could result in repeated work when runs are resumed.
The icon for the Task, it will appear in the logs. You can use the name of a
company in lowercase, e.g. “github”. Or any icon name that Tabler Icons supports.
An optional object that exposes settings for the remote callback feature.
Enabling this feature will expose a callbackUrl property on the callback’s Task parameter. Additionally, io.runTask() will now return a Promise that resolves with the body of the first request sent to that URL.
An optional callback that will be called when the Task fails. You can perform
logic in here and optionally return a custom error object. Returning an object with { retryAt: Date, error?: Error } will retry the Task at the specified Date. You can also just return a new Error object to throw a new error. Returning null or undefined will rethrow the original error. If you want to force retrying to be skipped, return { skipRetrying: true }.
A Promise that resolves with the returned value of the callback.
If the remote callback feature options.callback is enabled, the Promise will instead resolve with the body of the first request sent to task.callbackUrl.
client.defineJob({ id:"alert-on-new-github-issues", name:"Alert on new GitHub issues", version:"1.0.0", trigger: github.triggers.repo({ event: events.onIssueOpened, owner:"triggerdotdev", repo:"trigger.dev",}),run:async(payload, io, ctx)=>{const record =await io.runTask("sync-github-issue",async(task)=>{return prisma.githubIssues.create({ data:{number: payload.issue.number, title: payload.issue.title, body: payload.issue.body, url: payload.issue.html_url, repo: payload.repository.full_name, owner: payload.repository.owner.login,},});},//this is optional{ name:"Sync GitHub Issue", icon:"github"});},});