Skip to content

Commit a40e6c4

Browse files
committed
decrease snapshot poller logs
1 parent 974ce1e commit a40e6c4

3 files changed

Lines changed: 48 additions & 57 deletions

File tree

packages/cli-v3/src/entryPoints/managed/execution.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -240,11 +240,10 @@ export class RunExecution {
240240
}
241241

242242
if (snapshot.friendlyId === this.currentSnapshotId) {
243-
this.sendDebugLog("handleSnapshotChange: snapshot not changed", snapshotMetadata);
244-
return;
243+
return;
245244
}
246245

247-
this.sendDebugLog(`snapshot change: ${snapshot.executionStatus}`, snapshotMetadata);
246+
this.sendDebugLog(`snapshot has changed to: ${snapshot.executionStatus}`, snapshotMetadata);
248247

249248
// Reset the snapshot poll interval so we don't do unnecessary work
250249
this.snapshotPoller?.resetCurrentInterval();
@@ -897,7 +896,7 @@ export class RunExecution {
897896
this.lastHeartbeat = new Date();
898897
}
899898

900-
sendDebugLog(
899+
private sendDebugLog(
901900
message: string,
902901
properties?: SendDebugLogOptions["properties"],
903902
runIdOverride?: string
Lines changed: 41 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { WorkloadHttpClient } from "@trigger.dev/core/v3/runEngineWorker";
2-
import { RunLogger } from "./logger.js";
2+
import { RunLogger, SendDebugLogOptions } from "./logger.js";
33
import { IntervalService, RunExecutionData } from "@trigger.dev/core/v3";
44

55
export type RunExecutionSnapshotPollerOptions = {
@@ -14,89 +14,65 @@ export type RunExecutionSnapshotPollerOptions = {
1414
export class RunExecutionSnapshotPoller {
1515
private runFriendlyId: string;
1616
private snapshotFriendlyId: string;
17+
private enabled: boolean;
1718

1819
private readonly httpClient: WorkloadHttpClient;
1920
private readonly logger: RunLogger;
20-
private readonly snapshotPollIntervalMs: number;
2121
private readonly handleSnapshotChange: (runData: RunExecutionData) => Promise<void>;
2222
private readonly poller: IntervalService;
2323

2424
constructor(opts: RunExecutionSnapshotPollerOptions) {
25+
this.enabled = false;
26+
2527
this.runFriendlyId = opts.runFriendlyId;
2628
this.snapshotFriendlyId = opts.snapshotFriendlyId;
2729
this.httpClient = opts.httpClient;
2830
this.logger = opts.logger;
29-
this.snapshotPollIntervalMs = opts.snapshotPollIntervalSeconds * 1000;
3031
this.handleSnapshotChange = opts.handleSnapshotChange;
3132

32-
this.logger.sendDebugLog({
33-
runId: this.runFriendlyId,
34-
message: "RunExecutionSnapshotPoller",
35-
properties: {
36-
runFriendlyId: this.runFriendlyId,
37-
snapshotFriendlyId: this.snapshotFriendlyId,
38-
snapshotPollIntervalSeconds: opts.snapshotPollIntervalSeconds,
39-
},
40-
});
33+
const intervalMs = opts.snapshotPollIntervalSeconds * 1000;
4134

4235
this.poller = new IntervalService({
4336
onInterval: async () => {
44-
if (!this.runFriendlyId) {
45-
this.logger.sendDebugLog({
46-
runId: this.runFriendlyId,
47-
message: "Skipping snapshot poll, no run ID",
48-
});
49-
return;
50-
}
51-
52-
this.logger.sendDebugLog({
53-
runId: this.runFriendlyId,
54-
message: "Polling for latest snapshot",
55-
});
56-
57-
this.logger.sendDebugLog({
58-
runId: this.runFriendlyId,
59-
message: `snapshot poll: started`,
60-
properties: {
61-
snapshotId: this.snapshotFriendlyId,
62-
},
63-
});
37+
this.sendDebugLog("polling for latest snapshot");
6438

6539
const response = await this.httpClient.getRunExecutionData(this.runFriendlyId);
6640

6741
if (!response.success) {
68-
this.logger.sendDebugLog({
69-
runId: this.runFriendlyId,
70-
message: "Snapshot poll failed",
71-
properties: {
72-
error: response.error,
73-
},
74-
});
75-
76-
this.logger.sendDebugLog({
77-
runId: this.runFriendlyId,
78-
message: `snapshot poll: failed`,
79-
properties: {
80-
snapshotId: this.snapshotFriendlyId,
81-
error: response.error,
82-
},
83-
});
42+
this.sendDebugLog("failed to get run execution data", { error: response.error });
43+
return;
44+
}
8445

46+
if (!this.enabled) {
47+
this.sendDebugLog("poller disabled, skipping snapshot change handler");
8548
return;
8649
}
8750

8851
await this.handleSnapshotChange(response.data.execution);
8952
},
90-
intervalMs: this.snapshotPollIntervalMs,
53+
intervalMs,
9154
leadingEdge: false,
9255
onError: async (error) => {
93-
this.logger.sendDebugLog({
94-
runId: this.runFriendlyId,
95-
message: "Failed to poll for snapshot",
96-
properties: { error: error instanceof Error ? error.message : String(error) },
56+
this.sendDebugLog("failed to poll for snapshot", {
57+
error: error instanceof Error ? error.message : String(error),
9758
});
9859
},
9960
});
61+
62+
this.sendDebugLog("created");
63+
}
64+
65+
private sendDebugLog(message: string, properties?: SendDebugLogOptions["properties"]) {
66+
this.logger.sendDebugLog({
67+
runId: this.runFriendlyId,
68+
message: `[poller] ${message}`,
69+
properties: {
70+
...properties,
71+
runId: this.runFriendlyId,
72+
snapshotId: this.snapshotFriendlyId,
73+
pollIntervalMs: this.poller.intervalMs,
74+
},
75+
});
10076
}
10177

10278
resetCurrentInterval() {
@@ -112,10 +88,22 @@ export class RunExecutionSnapshotPoller {
11288
}
11389

11490
start() {
91+
if (this.enabled) {
92+
this.sendDebugLog("already started");
93+
return;
94+
}
95+
96+
this.enabled = true;
11597
this.poller.start();
11698
}
11799

118100
stop() {
101+
if (!this.enabled) {
102+
this.sendDebugLog("already stopped");
103+
return;
104+
}
105+
106+
this.enabled = false;
119107
this.poller.stop();
120108
}
121109
}

packages/core/src/v3/utils/interval.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ export class IntervalService {
6161
this.resetCurrentInterval();
6262
}
6363

64+
get intervalMs() {
65+
return this._intervalMs;
66+
}
67+
6468
#doInterval = async () => {
6569
this.#clearNextInterval();
6670

0 commit comments

Comments
 (0)