#Typed job invocations

1 messages · Page 1 of 1 (latest)

amber sigil
#

Typed job invocations

simple dagger
#

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

trail escarp
#

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
  })
GitHub

Provide environment information System: OS: macOS 11.7.5 CPU: (8) x64 Intel(R) Xeon(R) CPU E5-1620 v2 @ 3.70GHz Memory: 153.83 MB / 32.00 GB Shell: 3.2.57 - /bin/bash Binaries: Node: 18.17.1 - /usr...

simple dagger
#

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?

trail escarp
#

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

simple dagger
#

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

patent oracle
#

Yea that’s a regression, will investigate 👍

simple dagger
patent oracle
#

Okay that's been fixed in 2.3.10, you can upgrade your packages by running npx @trigger.dev/cli@latest update

simple dagger
#

I didn't make the fix but I think you should use the jobVarName.invoke() function.

#

We need to hide that other one

#

Hopefully the types are working for that now in the latest version