MCPcopy Index your code
hub / github.com/triggerdotdev/trigger.dev / invokeAndWaitForCompletion

Method invokeAndWaitForCompletion

packages/trigger-sdk/src/job.ts:269–338  ·  view source on GitHub ↗
(
    cacheKey: string | string[],
    payload: TriggerInvokeType<TTrigger>,
    timeoutInSeconds: number = 60 * 60, // 1 hour
    options: Prettify<Pick<InvokeOptions, "accountId" | "context">> = {}
  )

Source from the content-addressed store, hash-verified

267 }
268
269 async invokeAndWaitForCompletion(
270 cacheKey: string | string[],
271 payload: TriggerInvokeType<TTrigger>,
272 timeoutInSeconds: number = 60 * 60, // 1 hour
273 options: Prettify<Pick<InvokeOptions, "accountId" | "context">> = {}
274 ): Promise<RunNotification<TOutput>> {
275 const triggerClient = this.client;
276
277 if (!triggerClient) {
278 throw new Error(
279 "Cannot invoke a job that is not attached to a client. Make sure you attach the job to a client before invoking it."
280 );
281 }
282
283 const runStore = runLocalStorage.getStore();
284
285 if (!runStore) {
286 throw new Error(
287 "Cannot invoke a job from outside of a run using invokeAndWaitForCompletion. Make sure you are running the job from within a run or use the invoke method instead."
288 );
289 }
290
291 const { io, ctx } = runStore;
292
293 return (await io.runTask(
294 cacheKey,
295 async (task) => {
296 const parsedPayload = this.trigger.event.parseInvokePayload
297 ? this.trigger.event.parseInvokePayload(payload)
298 ? payload
299 : undefined
300 : payload;
301
302 const result = await triggerClient.invokeJob(this.id, parsedPayload, {
303 idempotencyKey: task.idempotencyKey,
304 callbackUrl: task.callbackUrl ?? undefined,
305 ...options,
306 });
307
308 task.outputProperties = [
309 {
310 label: "Run",
311 text: result.id,
312 url: `/orgs/${ctx.organization.slug}/projects/${ctx.project.slug}/jobs/${this.id}/runs/${result.id}/trigger`,
313 },
314 ];
315
316 return {}; // we don't want to return anything here, we just want to wait for the callback
317 },
318 {
319 name: `Manually Invoke '${this.name}' and wait for completion`,
320 params: payload,
321 properties: [
322 {
323 label: "Job",
324 text: this.id,
325 url: `/orgs/${ctx.organization.slug}/projects/${ctx.project.slug}/jobs/${this.id}`,
326 },

Callers 2

invoke.tsFile · 0.80

Calls 3

getStoreMethod · 0.45
runTaskMethod · 0.45
invokeJobMethod · 0.45

Tested by

no test coverage detected