Skip to content

Commit 3df8158

Browse files
committed
Unfriendly IDs
1 parent a24644b commit 3df8158

38 files changed

+457
-233
lines changed

apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.v3.$projectParam.test.tasks.$taskParam/route.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ export const action: ActionFunction = async ({ request, params }) => {
121121
);
122122
}
123123

124-
logger.error("Failed to start a test run", { error: e });
124+
logger.error("Failed to start a test run", { error: e instanceof Error ? e.message : e });
125125

126126
return redirectBackWithErrorMessage(
127127
request,

apps/webapp/app/routes/api.v1.tasks.$taskId.trigger.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ const { action, loader } = createActionApiRoute(
9696
return json(
9797
{
9898
id: run.friendlyId,
99-
internalId: run.id,
10099
},
101100
{
102101
headers: $responseHeaders,

apps/webapp/app/routes/api.v1.worker-actions.runs.$runId.snapshots.$snapshotId.attempts.complete.ts renamed to apps/webapp/app/routes/api.v1.worker-actions.runs.$runFriendlyId.snapshots.$snapshotFriendlyId.attempts.complete.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ export const action = createActionWorkerApiRoute(
1010
{
1111
body: WorkerApiRunAttemptCompleteRequestBody,
1212
params: z.object({
13-
runId: z.string(),
14-
snapshotId: z.string(),
13+
runFriendlyId: z.string(),
14+
snapshotFriendlyId: z.string(),
1515
}),
1616
},
1717
async ({
@@ -20,11 +20,11 @@ export const action = createActionWorkerApiRoute(
2020
params,
2121
}): Promise<TypedResponse<WorkerApiRunAttemptCompleteResponseBody>> => {
2222
const { completion } = body;
23-
const { runId, snapshotId } = params;
23+
const { runFriendlyId, snapshotFriendlyId } = params;
2424

2525
const completeResult = await authenticatedWorker.completeRunAttempt({
26-
runId,
27-
snapshotId,
26+
runFriendlyId,
27+
snapshotFriendlyId,
2828
completion,
2929
});
3030

apps/webapp/app/routes/api.v1.worker-actions.runs.$runId.snapshots.$snapshotId.attempts.start.ts renamed to apps/webapp/app/routes/api.v1.worker-actions.runs.$runFriendlyId.snapshots.$snapshotFriendlyId.attempts.start.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,20 @@ export const action = createActionWorkerApiRoute(
1010
{
1111
body: WorkerApiRunAttemptStartRequestBody,
1212
params: z.object({
13-
runId: z.string(),
14-
snapshotId: z.string(),
13+
runFriendlyId: z.string(),
14+
snapshotFriendlyId: z.string(),
1515
}),
1616
},
1717
async ({
1818
authenticatedWorker,
1919
body,
2020
params,
2121
}): Promise<TypedResponse<WorkerApiRunAttemptStartResponseBody>> => {
22-
const { runId, snapshotId } = params;
22+
const { runFriendlyId, snapshotFriendlyId } = params;
2323

2424
const runExecutionData = await authenticatedWorker.startRunAttempt({
25-
runId,
26-
snapshotId,
25+
runFriendlyId,
26+
snapshotFriendlyId,
2727
isWarmStart: body.isWarmStart,
2828
});
2929

apps/webapp/app/routes/api.v1.worker-actions.runs.$runId.snapshots.$snapshotId.heartbeat.ts renamed to apps/webapp/app/routes/api.v1.worker-actions.runs.$runFriendlyId.snapshots.$snapshotFriendlyId.heartbeat.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@ import { createActionWorkerApiRoute } from "~/services/routeBuilders/apiBuilder.
66
export const action = createActionWorkerApiRoute(
77
{
88
params: z.object({
9-
runId: z.string(),
10-
snapshotId: z.string(),
9+
runFriendlyId: z.string(),
10+
snapshotFriendlyId: z.string(),
1111
}),
1212
},
1313
async ({
1414
authenticatedWorker,
1515
params,
1616
}): Promise<TypedResponse<WorkloadHeartbeatResponseBody>> => {
17-
const { runId, snapshotId } = params;
17+
const { runFriendlyId, snapshotFriendlyId } = params;
1818

1919
await authenticatedWorker.heartbeatRun({
20-
runId,
21-
snapshotId,
20+
runFriendlyId,
21+
snapshotFriendlyId,
2222
});
2323

2424
return json({ ok: true });

apps/webapp/app/routes/api.v1.worker-actions.runs.$runId.snapshots.$snapshotId.wait.duration.ts renamed to apps/webapp/app/routes/api.v1.worker-actions.runs.$runFriendlyId.snapshots.$snapshotFriendlyId.wait.duration.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,20 @@ export const action = createActionWorkerApiRoute(
1010
{
1111
body: WorkerApiWaitForDurationRequestBody,
1212
params: z.object({
13-
runId: z.string(),
14-
snapshotId: z.string(),
13+
runFriendlyId: z.string(),
14+
snapshotFriendlyId: z.string(),
1515
}),
1616
},
1717
async ({
1818
authenticatedWorker,
1919
body,
2020
params,
2121
}): Promise<TypedResponse<WorkerApiWaitForDurationResponseBody>> => {
22-
const { runId, snapshotId } = params;
22+
const { runFriendlyId, snapshotFriendlyId } = params;
2323

2424
const waitResult = await authenticatedWorker.waitForDuration({
25-
runId,
26-
snapshotId,
25+
runFriendlyId,
26+
snapshotFriendlyId,
2727
date: body.date,
2828
});
2929

apps/webapp/app/routes/api.v1.worker-actions.runs.$runId.snapshots.latest.ts renamed to apps/webapp/app/routes/api.v1.worker-actions.runs.$runFriendlyId.snapshots.latest.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@ import { createLoaderWorkerApiRoute } from "~/services/routeBuilders/apiBuilder.
66
export const loader = createLoaderWorkerApiRoute(
77
{
88
params: z.object({
9-
runId: z.string(),
9+
runFriendlyId: z.string(),
1010
}),
1111
},
1212
async ({
1313
authenticatedWorker,
1414
params,
1515
}): Promise<TypedResponse<WorkerApiRunLatestSnapshotResponseBody>> => {
16-
const { runId } = params;
16+
const { runFriendlyId } = params;
1717

1818
const executionData = await authenticatedWorker.getLatestSnapshot({
19-
runId,
19+
runFriendlyId,
2020
});
2121

2222
if (!executionData) {

apps/webapp/app/v3/handleSocketIo.server.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -455,12 +455,12 @@ function createWorkerNamespace(io: Server) {
455455
clearInterval(interval);
456456
});
457457

458-
socket.on("run:subscribe", async ({ version, runIds }) => {
459-
logger.debug("run:subscribe", { version, runIds });
458+
socket.on("run:subscribe", async ({ version, runFriendlyIds }) => {
459+
logger.debug("run:subscribe", { version, runFriendlyIds });
460460

461461
const settledResult = await Promise.allSettled(
462-
runIds.map((runId) => {
463-
const room = roomFromRunId(runId);
462+
runFriendlyIds.map((friendlyId) => {
463+
const room = roomFromFriendlyRunId(friendlyId);
464464

465465
logger.debug("Joining room", { room });
466466

@@ -472,7 +472,7 @@ function createWorkerNamespace(io: Server) {
472472
for (const result of settledResult) {
473473
if (result.status === "rejected") {
474474
logger.error("Error joining room", {
475-
runIds,
475+
runFriendlyIds,
476476
error: result.reason instanceof Error ? result.reason.message : result.reason,
477477
});
478478
}
@@ -484,12 +484,12 @@ function createWorkerNamespace(io: Server) {
484484
});
485485
});
486486

487-
socket.on("run:unsubscribe", async ({ version, runIds }) => {
488-
logger.debug("run:unsubscribe", { version, runIds });
487+
socket.on("run:unsubscribe", async ({ version, runFriendlyIds }) => {
488+
logger.debug("run:unsubscribe", { version, runFriendlyIds });
489489

490490
const settledResult = await Promise.allSettled(
491-
runIds.map((runId) => {
492-
const room = roomFromRunId(runId);
491+
runFriendlyIds.map((friendlyId) => {
492+
const room = roomFromFriendlyRunId(friendlyId);
493493

494494
logger.debug("Leaving room", { room });
495495

@@ -501,7 +501,7 @@ function createWorkerNamespace(io: Server) {
501501
for (const result of settledResult) {
502502
if (result.status === "rejected") {
503503
logger.error("Error leaving room", {
504-
runIds,
504+
runFriendlyIds,
505505
error: result.reason instanceof Error ? result.reason.message : result.reason,
506506
});
507507
}
@@ -517,6 +517,6 @@ function createWorkerNamespace(io: Server) {
517517
return worker;
518518
}
519519

520-
function roomFromRunId(runId: string) {
521-
return `run:${runId}`;
520+
export function roomFromFriendlyRunId(id: string) {
521+
return `room:${id}`;
522522
}

apps/webapp/app/v3/runEngineHandlers.server.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ import { logger } from "~/services/logger.server";
55
import { safeJsonParse } from "~/utils/json";
66
import type { Attributes } from "@opentelemetry/api";
77
import { reportInvocationUsage } from "~/services/platform.v3.server";
8-
import { socketIo } from "./handleSocketIo.server";
8+
import { roomFromFriendlyRunId, socketIo } from "./handleSocketIo.server";
99
import { engine } from "./runEngine.server";
1010
import { PerformTaskRunAlertsService } from "./services/alerts/performTaskRunAlerts.server";
11+
import { RunId } from "@trigger.dev/core/v3/apps";
1112

1213
export function registerRunEngineEventBusHandlers() {
1314
engine.eventBus.on("runSucceeded", async ({ time, run }) => {
@@ -286,7 +287,12 @@ export function registerRunEngineEventBusHandlers() {
286287
logger.debug("[workerNotification] Notifying worker", { time, runId: run.id });
287288

288289
try {
289-
socketIo.workerNamespace.to(`run:${run.id}`).emit("run:notify", { version: "1", run });
290+
const runFriendlyId = RunId.toFriendlyId(run.id);
291+
const room = roomFromFriendlyRunId(runFriendlyId);
292+
293+
socketIo.workerNamespace
294+
.to(room)
295+
.emit("run:notify", { version: "1", run: { friendlyId: runFriendlyId } });
290296
} catch (error) {
291297
logger.error("[workerNotification] Failed to notify worker", {
292298
error: error instanceof Error ? error.message : error,

apps/webapp/app/v3/services/batchTriggerV2.server.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -709,18 +709,18 @@ export class BatchTriggerV2Service extends BaseService {
709709
| { status: "ERROR"; error: string; workingIndex: number }
710710
> {
711711
// Grab the next PROCESSING_BATCH_SIZE runIds
712-
const runIds = batch.runIds.slice(currentIndex, currentIndex + batchSize);
712+
const runFriendlyIds = batch.runIds.slice(currentIndex, currentIndex + batchSize);
713713

714714
logger.debug("[BatchTriggerV2][processBatchTaskRun] Processing batch items", {
715715
batchId: batch.friendlyId,
716716
currentIndex,
717-
runIds,
717+
runIds: runFriendlyIds,
718718
runCount: batch.runCount,
719719
});
720720

721721
// Combine the "window" between currentIndex and currentIndex + PROCESSING_BATCH_SIZE with the runId and the item in the payload which is an array
722-
const itemsToProcess = runIds.map((runId, index) => ({
723-
runId,
722+
const itemsToProcess = runFriendlyIds.map((runFriendlyId, index) => ({
723+
runFriendlyId,
724724
item: items[index + currentIndex],
725725
}));
726726

@@ -757,13 +757,13 @@ export class BatchTriggerV2Service extends BaseService {
757757
async #processBatchTaskRunItem(
758758
batch: BatchTaskRun,
759759
environment: AuthenticatedEnvironment,
760-
task: { runId: string; item: BatchTriggerTaskV2RequestBody["items"][number] },
760+
task: { runFriendlyId: string; item: BatchTriggerTaskV2RequestBody["items"][number] },
761761
currentIndex: number,
762762
options?: BatchTriggerTaskServiceOptions
763763
) {
764764
logger.debug("[BatchTriggerV2][processBatchTaskRunItem] Processing item", {
765765
batchId: batch.friendlyId,
766-
runId: task.runId,
766+
runId: task.runFriendlyId,
767767
currentIndex,
768768
});
769769

@@ -786,12 +786,12 @@ export class BatchTriggerV2Service extends BaseService {
786786
spanParentAsLink: options?.spanParentAsLink,
787787
batchId: batch.friendlyId,
788788
skipChecks: true,
789-
runId: task.runId,
789+
runFriendlyId: task.runFriendlyId,
790790
}
791791
);
792792

793793
if (!run) {
794-
throw new Error(`Failed to trigger run ${task.runId} for batch ${batch.friendlyId}`);
794+
throw new Error(`Failed to trigger run ${task.runFriendlyId} for batch ${batch.friendlyId}`);
795795
}
796796

797797
await this._prisma.batchTaskRunItem.create({

0 commit comments

Comments
 (0)