Skip to content

Commit d3386e2

Browse files
committed
return worker group details from connect call
1 parent 482a98d commit d3386e2

File tree

4 files changed

+35
-12
lines changed

4 files changed

+35
-12
lines changed
Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import { json, TypedResponse } from "@remix-run/server-runtime";
2-
import {
3-
WorkerApiConnectRequestBody,
4-
WorkerApiConnectResponseBody,
5-
} from "@trigger.dev/worker";
2+
import { WorkerApiConnectRequestBody, WorkerApiConnectResponseBody } from "@trigger.dev/worker";
63
import { createActionWorkerApiRoute } from "~/services/routeBuilders/apiBuilder.server";
74

85
export const action = createActionWorkerApiRoute(
@@ -11,6 +8,12 @@ export const action = createActionWorkerApiRoute(
118
},
129
async ({ authenticatedWorker, body }): Promise<TypedResponse<WorkerApiConnectResponseBody>> => {
1310
await authenticatedWorker.connect(body.metadata);
14-
return json({ ok: true });
11+
return json({
12+
ok: true,
13+
workerGroup: {
14+
type: authenticatedWorker.type,
15+
name: authenticatedWorker.name,
16+
},
17+
});
1518
}
1619
);

apps/webapp/app/v3/services/worker/workerGroupTokenService.server.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ export class WorkerGroupTokenService extends WithRunEngine {
207207
prisma: this._prisma,
208208
engine: this._engine,
209209
type: WorkerInstanceGroupType.MANAGED,
210+
name: workerGroup.name,
210211
workerGroupId: workerGroup.id,
211212
workerInstanceId: workerInstance.id,
212213
masterQueue: workerGroup.masterQueue,
@@ -242,6 +243,7 @@ export class WorkerGroupTokenService extends WithRunEngine {
242243
prisma: this._prisma,
243244
engine: this._engine,
244245
type: WorkerInstanceGroupType.UNMANAGED,
246+
name: workerGroup.name,
245247
workerGroupId: workerGroup.id,
246248
workerInstanceId: workerInstance.id,
247249
masterQueue: workerGroup.masterQueue,
@@ -481,6 +483,7 @@ export type WorkerInstanceEnv = z.infer<typeof WorkerInstanceEnv>;
481483

482484
export type AuthenticatedWorkerInstanceOptions = WithRunEngineOptions<{
483485
type: WorkerInstanceGroupType;
486+
name: string;
484487
workerGroupId: string;
485488
workerInstanceId: string;
486489
masterQueue: string;
@@ -492,20 +495,22 @@ export type AuthenticatedWorkerInstanceOptions = WithRunEngineOptions<{
492495

493496
export class AuthenticatedWorkerInstance extends WithRunEngine {
494497
readonly type: WorkerInstanceGroupType;
498+
readonly name: string;
495499
readonly workerGroupId: string;
496500
readonly workerInstanceId: string;
497501
readonly masterQueue: string;
498502
readonly environment: RuntimeEnvironment | null;
499503
readonly deploymentId?: string;
500504
readonly backgroundWorkerId?: string;
501505

502-
// FIXME
506+
// FIXME: Required for unmanaged workers
503507
readonly isLatestDeployment = true;
504508

505509
constructor(opts: AuthenticatedWorkerInstanceOptions) {
506510
super({ prisma: opts.prisma, engine: opts.engine });
507511

508512
this.type = opts.type;
513+
this.name = opts.name;
509514
this.workerGroupId = opts.workerGroupId;
510515
this.workerInstanceId = opts.workerInstanceId;
511516
this.masterQueue = opts.masterQueue;
@@ -715,6 +720,7 @@ export class AuthenticatedWorkerInstance extends WithRunEngine {
715720
if (this.type === WorkerInstanceGroupType.MANAGED) {
716721
return {
717722
type: WorkerInstanceGroupType.MANAGED,
723+
name: this.name,
718724
workerGroupId: this.workerGroupId,
719725
workerInstanceId: this.workerInstanceId,
720726
masterQueue: this.masterQueue,
@@ -723,6 +729,7 @@ export class AuthenticatedWorkerInstance extends WithRunEngine {
723729

724730
return {
725731
type: WorkerInstanceGroupType.UNMANAGED,
732+
name: this.name,
726733
workerGroupId: this.workerGroupId,
727734
workerInstanceId: this.workerInstanceId,
728735
masterQueue: this.masterQueue,
@@ -761,12 +768,14 @@ export class AuthenticatedWorkerInstance extends WithRunEngine {
761768
export type WorkerGroupTokenAuthenticationResponse =
762769
| {
763770
type: typeof WorkerInstanceGroupType.MANAGED;
771+
name: string;
764772
workerGroupId: string;
765773
workerInstanceId: string;
766774
masterQueue: string;
767775
}
768776
| {
769777
type: typeof WorkerInstanceGroupType.UNMANAGED;
778+
name: string;
770779
workerGroupId: string;
771780
workerInstanceId: string;
772781
masterQueue: string;

packages/worker/src/supervisor/schemas.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ export type WorkerApiConnectRequestBody = z.infer<typeof WorkerApiConnectRequest
3333

3434
export const WorkerApiConnectResponseBody = z.object({
3535
ok: z.literal(true),
36+
workerGroup: z.object({
37+
type: z.string(),
38+
name: z.string(),
39+
}),
3640
});
3741
export type WorkerApiConnectResponseBody = z.infer<typeof WorkerApiConnectResponseBody>;
3842

packages/worker/src/supervisor/session.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,17 +100,17 @@ export class SupervisorSession extends EventEmitter<WorkerEvents> {
100100
extraHeaders: getDefaultWorkerHeaders(this.opts),
101101
});
102102
this.socket.on("run:notify", ({ version, run }) => {
103-
console.log("[WorkerSession] Received run notification", { version, run });
103+
console.log("[WorkerSession][WS] Received run notification", { version, run });
104104
this.emit("runNotification", { time: new Date(), run });
105105
});
106106
this.socket.on("connect", () => {
107-
console.log("[WorkerSession] Connected to platform");
107+
console.log("[WorkerSession][WS] Connected to platform");
108108
});
109109
this.socket.on("connect_error", (error) => {
110-
console.error("[WorkerSession] Connection error", { error });
110+
console.error("[WorkerSession][WS] Connection error", { error });
111111
});
112112
this.socket.on("disconnect", (reason, description) => {
113-
console.log("[WorkerSession] Disconnected from platform", { reason, description });
113+
console.log("[WorkerSession][WS] Disconnected from platform", { reason, description });
114114
});
115115
}
116116

@@ -122,10 +122,17 @@ export class SupervisorSession extends EventEmitter<WorkerEvents> {
122122
});
123123

124124
if (!connect.success) {
125-
console.error("[WorkerSession] Failed to connect via HTTP client", { error: connect.error });
126-
throw new Error("[WorkerSession] Failed to connect via HTTP client");
125+
console.error("[WorkerSession][HTTP] Failed to connect", { error: connect.error });
126+
throw new Error("[WorkerSession][HTTP] Failed to connect");
127127
}
128128

129+
const { workerGroup } = connect.data;
130+
131+
console.log("[WorkerSession][HTTP] Connected to platform", {
132+
type: workerGroup.type,
133+
name: workerGroup.name,
134+
});
135+
129136
this.queueConsumer.start();
130137
this.heartbeatService.start();
131138
this.createSocket();

0 commit comments

Comments
 (0)