Fixed Job.attachToClient
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@trigger.dev/sdk": patch
|
||||
---
|
||||
|
||||
Fixed Job.attachToClient
|
||||
@@ -121,8 +121,8 @@ export class Job<
|
||||
* Attaches the job to a client. This is called automatically when you define a job using `client.defineJob()`.
|
||||
*/
|
||||
attachToClient(client: TriggerClient) {
|
||||
this.client = client;
|
||||
this.trigger.attachToJob(client, this);
|
||||
client.attach(this);
|
||||
return this;
|
||||
}
|
||||
|
||||
get id() {
|
||||
@@ -185,8 +185,8 @@ export class Job<
|
||||
typeof this.options.concurrencyLimit === "number"
|
||||
? this.options.concurrencyLimit
|
||||
: typeof this.options.concurrencyLimit === "object"
|
||||
? { id: this.options.concurrencyLimit.id, limit: this.options.concurrencyLimit.limit }
|
||||
: undefined,
|
||||
? { id: this.options.concurrencyLimit.id, limit: this.options.concurrencyLimit.limit }
|
||||
: undefined,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -739,7 +739,8 @@ export class TriggerClient {
|
||||
|
||||
attach(job: Job<Trigger<any>, any>): void {
|
||||
this.#registeredJobs[job.id] = job;
|
||||
job.attachToClient(this);
|
||||
job.trigger.attachToJob(this, job);
|
||||
job.client = this;
|
||||
}
|
||||
|
||||
attachDynamicTrigger(trigger: DynamicTrigger<any, any>): void {
|
||||
@@ -1683,15 +1684,15 @@ export class TriggerClient {
|
||||
auth:
|
||||
resolvedAuth.type === "apiKey"
|
||||
? {
|
||||
type: "apiKey",
|
||||
accessToken: resolvedAuth.token,
|
||||
additionalFields: resolvedAuth.additionalFields,
|
||||
}
|
||||
type: "apiKey",
|
||||
accessToken: resolvedAuth.token,
|
||||
additionalFields: resolvedAuth.additionalFields,
|
||||
}
|
||||
: {
|
||||
type: "oauth2",
|
||||
accessToken: resolvedAuth.token,
|
||||
additionalFields: resolvedAuth.additionalFields,
|
||||
},
|
||||
type: "oauth2",
|
||||
accessToken: resolvedAuth.token,
|
||||
additionalFields: resolvedAuth.additionalFields,
|
||||
},
|
||||
};
|
||||
} catch (resolverError) {
|
||||
if (resolverError instanceof Error) {
|
||||
@@ -1708,9 +1709,8 @@ export class TriggerClient {
|
||||
|
||||
return {
|
||||
ok: false,
|
||||
error: `Auth could not be resolved for ${
|
||||
integration.id
|
||||
}: auth resolver threw an unknown error: ${JSON.stringify(resolverError)}`,
|
||||
error: `Auth could not be resolved for ${integration.id
|
||||
}: auth resolver threw an unknown error: ${JSON.stringify(resolverError)}`,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1737,8 +1737,8 @@ export class TriggerClient {
|
||||
typeof job.options.concurrencyLimit === "number"
|
||||
? job.options.concurrencyLimit
|
||||
: typeof job.options.concurrencyLimit === "object"
|
||||
? { id: job.options.concurrencyLimit.id, limit: job.options.concurrencyLimit.limit }
|
||||
: undefined,
|
||||
? { id: job.options.concurrencyLimit.id, limit: job.options.concurrencyLimit.limit }
|
||||
: undefined,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { createExpressServer } from "@trigger.dev/express";
|
||||
import { TriggerClient, invokeTrigger } from "@trigger.dev/sdk";
|
||||
import { Job, TriggerClient, invokeTrigger } from "@trigger.dev/sdk";
|
||||
import fs from "node:fs";
|
||||
import fsPromises from "node:fs/promises";
|
||||
|
||||
@@ -104,4 +104,14 @@ client.defineJob({
|
||||
},
|
||||
});
|
||||
|
||||
const job = new Job({
|
||||
id: "attach-to-client",
|
||||
name: "Attach to Client",
|
||||
version: "1.0.0",
|
||||
trigger: invokeTrigger(),
|
||||
run: async (payload, io, ctx) => {
|
||||
await io.logger.info("Hello from job", { ctx })
|
||||
},
|
||||
}).attachToClient(client);
|
||||
|
||||
createExpressServer(client);
|
||||
|
||||
Reference in New Issue
Block a user