Skip to content

Commit c5491f0

Browse files
matt-aitkenTrigger.dev RepoOps
authored andcommitted
perf(webapp,run-engine): skip dev worker notifications for non-dev runs
Run state notifications were broadcast to both the deployed worker and dev worker socket.io namespaces for every run, regardless of environment. The dev worker namespace only accepts connections from development environments, so that second broadcast was discarded for every non-development run. Notifications now reach the dev worker namespace only for runs in a development environment. This removes the redundant broadcast and roughly halves the Redis pub/sub traffic generated by the run notification path. Mono-RevId: 84cb5aead09067daeb979d793e3974c2a1da57c8
1 parent fdec5a0 commit c5491f0

3 files changed

Lines changed: 14 additions & 4 deletions

File tree

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -690,9 +690,11 @@ export function registerRunEngineEventBusHandlers() {
690690
.emit("run:notify", { version: "1", run: { friendlyId: runFriendlyId } });
691691

692692
//send the notification to connected dev workers
693-
socketIo.devWorkerNamespace
694-
.to(room)
695-
.emit("run:notify", { version: "1", run: { friendlyId: runFriendlyId } });
693+
if (snapshot.environmentType === "DEVELOPMENT") {
694+
socketIo.devWorkerNamespace
695+
.to(room)
696+
.emit("run:notify", { version: "1", run: { friendlyId: runFriendlyId } });
697+
}
696698

697699
if (!env.RUN_ENGINE_DEBUG_WORKER_NOTIFICATIONS) {
698700
return;

internal-packages/run-engine/src/engine/eventBus.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import type { FlushedRunMetadata, TaskRunError } from "@trigger.dev/core/v3";
2-
import type { TaskRunExecutionStatus, TaskRunStatus } from "@trigger.dev/database";
2+
import type {
3+
RuntimeEnvironmentType,
4+
TaskRunExecutionStatus,
5+
TaskRunStatus,
6+
} from "@trigger.dev/database";
37
import type { EventEmitter } from "events";
48
import type { AuthenticatedEnvironment } from "../shared/index.js";
59

@@ -324,6 +328,7 @@ export type EventBusEvents = {
324328
snapshot: {
325329
id: string;
326330
executionStatus: TaskRunExecutionStatus;
331+
environmentType: RuntimeEnvironmentType;
327332
};
328333
},
329334
];
@@ -383,6 +388,7 @@ export async function sendNotificationToWorker({
383388
snapshot: {
384389
id: string;
385390
executionStatus: TaskRunExecutionStatus;
391+
environmentType: RuntimeEnvironmentType;
386392
};
387393
eventBus: EventBus;
388394
}) {
@@ -394,6 +400,7 @@ export async function sendNotificationToWorker({
394400
snapshot: {
395401
id: snapshot.id,
396402
executionStatus: snapshot.executionStatus,
403+
environmentType: snapshot.environmentType,
397404
},
398405
});
399406
}

internal-packages/run-engine/src/engine/tests/waitpoints.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,7 @@ describe("RunEngine Waitpoints", () => {
393393
assertNonNullable(event);
394394
const notificationEvent = event as EventBusEventArgs<"workerNotification">[0];
395395
expect(notificationEvent.run.id).toBe(run.id);
396+
expect(notificationEvent.snapshot.environmentType).toBe("PRODUCTION");
396397

397398
const executionData2 = await engine.getRunExecutionData({ runId: run.id });
398399
expect(executionData2?.snapshot.executionStatus).toBe("EXECUTING");

0 commit comments

Comments
 (0)