#Typed job invocations
1 messages · Page 1 of 1 (latest)
Are you invoking from inside another job?
You should use invoke directly on your job, which you assigned to an exported variables
So the Job is exported:
export const exampleJob = client.defineJob({
...
Then elsewhere you use the reference to the Job.
You can either invoke it but NOT wait for the result. Fire and forget. This works from your own code, outside of a Job run.
const jobRun = await exampleJob.invoke({ foo: "bar" });
Or from inside a different Job's run function you can do this:
client.defineJob({
id: "example-job2",
name: "Example job 2",
version: "1.0.1",
trigger: intervalTrigger({
seconds: 60,
}),
run: async (payload, io, ctx) => {
//
//invoke and wait for the result
//
const jobRun = await exampleJob.invokeAndWaitForCompletion("⚡", {
userId: "123",
tier: "free",
});
if (jobRun.ok) {
// The job run finished successfully
console.log(jobRun.output);
} else {
// The job run finished with an error
console.log(`The job failed with status ${jobRun.status}`, jobRun.error);
}
},
});
This is type safe
I'm having a similar issue. The exported define job looks fine. When I go to invoke I get no help. I made sure my zod version is the same as what trigger is using since I was also running into this issue:
https://github.com/triggerdotdev/trigger.dev/issues/727
await orderCompleteJob.invoke({
// no help
})
So I’d you do this you don’t get a type error?
await orderCompleteJob.invoke({
foo: 123
})
If that’s the case you might need to restart the TypeScript server in VSCode?
Yea, I've restarted vscode, restarted just typescript. Typescript seems to be working fine everywhere else. Just getting nothing. Using Typescript 5.3.3
Payload is listed as any
Yep you're totally right, I'm seeing the same thing with the any for the payload. This is a bug that we'll get fixed.
@patent oracle the invoke() calls have an issue where the types aren't going through for the payload
Yea that’s a regression, will investigate 👍
Okay that's been fixed in 2.3.10, you can upgrade your packages by running npx @trigger.dev/cli@latest update