(
cacheKey: string | string[],
payload: TriggerInvokeType<TTrigger>,
timeoutInSeconds: number = 60 * 60, // 1 hour
options: Prettify<Pick<InvokeOptions, "accountId" | "context">> = {}
)
| 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 | }, |
no test coverage detected