Skip to content

Commit aa74260

Browse files
authored
Dev command engine URL now configurable via the webapp (#1948)
* return dev engine url from config call * set and use engine url from dev config reply
1 parent f683fe8 commit aa74260

File tree

5 files changed

+23
-8
lines changed

5 files changed

+23
-8
lines changed

apps/webapp/app/env.server.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,9 @@ const EnvironmentSchema = z.object({
624624
/** The maximum concurrent local run processes executing at once in dev */
625625
DEV_MAX_CONCURRENT_RUNS: z.coerce.number().int().default(25),
626626

627+
/** The CLI should connect to this for dev runs */
628+
DEV_ENGINE_URL: z.string().default(process.env.APP_ORIGIN ?? "http://localhost:3030"),
629+
627630
LEGACY_RUN_ENGINE_WORKER_ENABLED: z.string().default(process.env.WORKER_ENABLED ?? "true"),
628631
LEGACY_RUN_ENGINE_WORKER_CONCURRENCY_WORKERS: z.coerce.number().int().default(2),
629632
LEGACY_RUN_ENGINE_WORKER_CONCURRENCY_TASKS_PER_WORKER: z.coerce.number().int().default(1),

apps/webapp/app/routes/engine.v1.dev.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export const loader = createLoaderApiRoute(
2121
dequeueIntervalWithRun: env.DEV_DEQUEUE_INTERVAL_WITH_RUN,
2222
dequeueIntervalWithoutRun: env.DEV_DEQUEUE_INTERVAL_WITHOUT_RUN,
2323
maxConcurrentRuns: env.DEV_MAX_CONCURRENT_RUNS,
24+
engineUrl: env.DEV_ENGINE_URL,
2425
});
2526
} catch (error) {
2627
logger.error("Failed to get dev settings", {

packages/cli-v3/src/apiClient.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,15 @@ import {
4545
} from "@trigger.dev/core/v3/workers";
4646

4747
export class CliApiClient {
48+
private engineURL: string;
49+
4850
constructor(
4951
public readonly apiURL: string,
5052
// TODO: consider making this required
5153
public readonly accessToken?: string
5254
) {
5355
this.apiURL = apiURL.replace(/\/$/, "");
56+
this.engineURL = this.apiURL;
5457
}
5558

5659
async createAuthorizationCode() {
@@ -418,6 +421,7 @@ export class CliApiClient {
418421
heartbeatRun: this.devHeartbeatRun.bind(this),
419422
startRunAttempt: this.devStartRunAttempt.bind(this),
420423
completeRunAttempt: this.devCompleteRunAttempt.bind(this),
424+
setEngineURL: this.setEngineURL.bind(this),
421425
} as const;
422426
}
423427

@@ -486,7 +490,7 @@ export class CliApiClient {
486490
throw new Error("devConfig: No access token");
487491
}
488492

489-
return wrapZodFetch(DevConfigResponseBody, `${this.apiURL}/engine/v1/dev/config`, {
493+
return wrapZodFetch(DevConfigResponseBody, `${this.engineURL}/engine/v1/dev/config`, {
490494
headers: {
491495
Authorization: `Bearer ${this.accessToken}`,
492496
Accept: "application/json",
@@ -503,7 +507,7 @@ export class CliApiClient {
503507
const maxRetries = 5;
504508
const retryDelay = 1000; // Start with 1 second delay
505509

506-
const eventSource = new EventSource(`${this.apiURL}/engine/v1/dev/presence`, {
510+
const eventSource = new EventSource(`${this.engineURL}/engine/v1/dev/presence`, {
507511
fetch: (input, init) =>
508512
fetch(input, {
509513
...init,
@@ -557,7 +561,7 @@ export class CliApiClient {
557561
throw new Error("devConfig: No access token");
558562
}
559563

560-
return wrapZodFetch(DevDequeueResponseBody, `${this.apiURL}/engine/v1/dev/dequeue`, {
564+
return wrapZodFetch(DevDequeueResponseBody, `${this.engineURL}/engine/v1/dev/dequeue`, {
561565
method: "POST",
562566
headers: {
563567
Authorization: `Bearer ${this.accessToken}`,
@@ -575,7 +579,7 @@ export class CliApiClient {
575579
throw new Error("devConfig: No access token");
576580
}
577581

578-
return wrapZodFetch(z.unknown(), `${this.apiURL}/engine/v1/dev/runs/${runId}/logs/debug`, {
582+
return wrapZodFetch(z.unknown(), `${this.engineURL}/engine/v1/dev/runs/${runId}/logs/debug`, {
579583
method: "POST",
580584
headers: {
581585
Authorization: `Bearer ${this.accessToken}`,
@@ -591,7 +595,7 @@ export class CliApiClient {
591595
): Promise<ApiResult<WorkloadRunLatestSnapshotResponseBody>> {
592596
return wrapZodFetch(
593597
WorkloadRunLatestSnapshotResponseBody,
594-
`${this.apiURL}/engine/v1/dev/runs/${runId}/snapshots/latest`,
598+
`${this.engineURL}/engine/v1/dev/runs/${runId}/snapshots/latest`,
595599
{
596600
method: "GET",
597601
headers: {
@@ -609,7 +613,7 @@ export class CliApiClient {
609613
): Promise<ApiResult<WorkloadHeartbeatResponseBody>> {
610614
return wrapZodFetch(
611615
WorkloadHeartbeatResponseBody,
612-
`${this.apiURL}/engine/v1/dev/runs/${runId}/snapshots/${snapshotId}/heartbeat`,
616+
`${this.engineURL}/engine/v1/dev/runs/${runId}/snapshots/${snapshotId}/heartbeat`,
613617
{
614618
method: "POST",
615619
headers: {
@@ -628,7 +632,7 @@ export class CliApiClient {
628632
): Promise<ApiResult<WorkloadRunAttemptStartResponseBody>> {
629633
return wrapZodFetch(
630634
WorkloadRunAttemptStartResponseBody,
631-
`${this.apiURL}/engine/v1/dev/runs/${runId}/snapshots/${snapshotId}/attempts/start`,
635+
`${this.engineURL}/engine/v1/dev/runs/${runId}/snapshots/${snapshotId}/attempts/start`,
632636
{
633637
method: "POST",
634638
headers: {
@@ -648,7 +652,7 @@ export class CliApiClient {
648652
): Promise<ApiResult<WorkloadRunAttemptCompleteResponseBody>> {
649653
return wrapZodFetch(
650654
WorkloadRunAttemptCompleteResponseBody,
651-
`${this.apiURL}/engine/v1/dev/runs/${runId}/snapshots/${snapshotId}/attempts/complete`,
655+
`${this.engineURL}/engine/v1/dev/runs/${runId}/snapshots/${snapshotId}/attempts/complete`,
652656
{
653657
method: "POST",
654658
headers: {
@@ -659,4 +663,8 @@ export class CliApiClient {
659663
}
660664
);
661665
}
666+
667+
private setEngineURL(engineURL: string) {
668+
this.engineURL = engineURL.replace(/\/$/, "");
669+
}
662670
}

packages/cli-v3/src/dev/devSupervisor.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ class DevSupervisor implements WorkerRuntime {
8484
logger.debug("[DevSupervisor] Got dev settings", { settings: settings.data });
8585
this.config = settings.data;
8686

87+
this.options.client.dev.setEngineURL(this.config.engineUrl);
88+
8789
const maxConcurrentRuns = Math.min(
8890
this.config.maxConcurrentRuns,
8991
this.options.args.maxConcurrentRuns ?? this.config.maxConcurrentRuns

packages/core/src/v3/schemas/api.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,7 @@ export const DevConfigResponseBody = z.object({
432432
dequeueIntervalWithRun: z.number(),
433433
dequeueIntervalWithoutRun: z.number(),
434434
maxConcurrentRuns: z.number(),
435+
engineUrl: z.string(),
435436
});
436437
export type DevConfigResponseBody = z.infer<typeof DevConfigResponseBody>;
437438

0 commit comments

Comments
 (0)