(
param1: string | TriggerInvokeType<TTrigger>,
param2: TriggerInvokeType<TTrigger> | InvokeOptions | undefined = undefined,
param3: InvokeOptions | undefined = undefined
)
| 200 | options?: InvokeOptions |
| 201 | ): Promise<{ id: string }>; |
| 202 | async invoke( |
| 203 | param1: string | TriggerInvokeType<TTrigger>, |
| 204 | param2: TriggerInvokeType<TTrigger> | InvokeOptions | undefined = undefined, |
| 205 | param3: InvokeOptions | undefined = undefined |
| 206 | ): Promise<{ id: string }> { |
| 207 | const triggerClient = this.client; |
| 208 | |
| 209 | if (!triggerClient) { |
| 210 | throw new Error( |
| 211 | "Cannot invoke a job that is not attached to a client. Make sure you attach the job to a client before invoking it." |
| 212 | ); |
| 213 | } |
| 214 | |
| 215 | const runStore = runLocalStorage.getStore(); |
| 216 | |
| 217 | if (typeof param1 === "string") { |
| 218 | if (!runStore) { |
| 219 | throw new Error( |
| 220 | "Cannot invoke a job from outside of a run when passing a cacheKey. Make sure you are running the job from within a run or use the invoke method without the cacheKey." |
| 221 | ); |
| 222 | } |
| 223 | |
| 224 | const options = param3 ?? {}; |
| 225 | |
| 226 | return await runStore.io.runTask( |
| 227 | param1, |
| 228 | async (task) => { |
| 229 | const result = await triggerClient.invokeJob(this.id, param2, { |
| 230 | idempotencyKey: task.idempotencyKey, |
| 231 | ...options, |
| 232 | }); |
| 233 | |
| 234 | task.outputProperties = [ |
| 235 | { |
| 236 | label: "Run", |
| 237 | text: result.id, |
| 238 | url: `/orgs/${runStore.ctx.organization.slug}/projects/${runStore.ctx.project.slug}/jobs/${this.id}/runs/${result.id}/trigger`, |
| 239 | }, |
| 240 | ]; |
| 241 | |
| 242 | return result; |
| 243 | }, |
| 244 | { |
| 245 | name: `Manually Invoke '${this.name}'`, |
| 246 | params: param2, |
| 247 | properties: [ |
| 248 | { |
| 249 | label: "Job", |
| 250 | text: this.id, |
| 251 | url: `/orgs/${runStore.ctx.organization.slug}/projects/${runStore.ctx.project.slug}/jobs/${this.id}`, |
| 252 | }, |
| 253 | { |
| 254 | label: "Env", |
| 255 | text: runStore.ctx.environment.slug, |
| 256 | }, |
| 257 | ], |
| 258 | } |
| 259 | ); |
no test coverage detected