@@ -3,7 +3,6 @@ import { env as stdEnv } from "std-env";
33import { readJSONFile } from "../utilities/fileSystem.js" ;
44import {
55 type CompleteRunAttemptResult ,
6- HeartbeatService ,
76 type RunExecutionData ,
87 SuspendedProcessError ,
98 type TaskRunExecutionMetrics ,
@@ -26,6 +25,7 @@ import { RunnerEnv } from "./managed/env.js";
2625import { MetadataClient } from "./managed/overrides.js" ;
2726import { RunLogger , SendDebugLogOptions } from "./managed/logger.js" ;
2827import { RunExecutionHeartbeat } from "./managed/heartbeat.js" ;
28+ import { RunExecutionSnapshotPoller } from "./managed/poller.js" ;
2929
3030const env = new RunnerEnv ( stdEnv ) ;
3131
@@ -54,8 +54,8 @@ class ManagedRunController {
5454 private socket : Socket < WorkloadServerToClientEvents , WorkloadClientToServerEvents > ;
5555 private readonly logger : RunLogger ;
5656
57- private readonly runHeartbeat : HeartbeatService ;
58- private readonly snapshotPoller : RunExecutionHeartbeat ;
57+ private readonly runHeartbeat : RunExecutionHeartbeat ;
58+ private readonly snapshotPoller : RunExecutionSnapshotPoller ;
5959
6060 constructor ( opts : ManagedRunControllerOptions ) {
6161 this . workerManifest = opts . workerManifest ;
@@ -100,55 +100,25 @@ class ManagedRunController {
100100 } ) ;
101101 }
102102
103- this . snapshotPoller = new RunExecutionHeartbeat ( {
103+ this . snapshotPoller = new RunExecutionSnapshotPoller ( {
104104 // @ts -expect-error
105105 runFriendlyId : env . TRIGGER_RUN_ID ,
106106 // @ts -expect-error
107107 snapshotFriendlyId : env . TRIGGER_SNAPSHOT_ID ,
108108 httpClient : this . httpClient ,
109109 logger : this . logger ,
110- heartbeatIntervalSeconds : this . heartbeatIntervalSeconds ,
110+ snapshotPollIntervalSeconds : this . snapshotPollIntervalSeconds ,
111+ handleSnapshotChange : this . handleSnapshotChange ,
111112 } ) ;
112113
113- this . runHeartbeat = new HeartbeatService ( {
114- heartbeat : async ( ) => {
115- if ( ! this . runFriendlyId || ! this . snapshotFriendlyId ) {
116- this . sendDebugLog ( {
117- runId : this . runFriendlyId ,
118- message : "Skipping heartbeat, no run ID or snapshot ID" ,
119- } ) ;
120- return ;
121- }
122-
123- this . sendDebugLog ( {
124- runId : this . runFriendlyId ,
125- message : "heartbeat: started" ,
126- } ) ;
127-
128- const response = await this . httpClient . heartbeatRun (
129- this . runFriendlyId ,
130- this . snapshotFriendlyId
131- ) ;
132-
133- if ( ! response . success ) {
134- this . sendDebugLog ( {
135- runId : this . runFriendlyId ,
136- message : "heartbeat: failed" ,
137- properties : {
138- error : response . error ,
139- } ,
140- } ) ;
141- }
142- } ,
143- intervalMs : this . heartbeatIntervalSeconds * 1000 ,
144- leadingEdge : false ,
145- onError : async ( error ) => {
146- this . sendDebugLog ( {
147- runId : this . runFriendlyId ,
148- message : "Failed to send heartbeat" ,
149- properties : { error : error instanceof Error ? error . message : String ( error ) } ,
150- } ) ;
151- } ,
114+ this . runHeartbeat = new RunExecutionHeartbeat ( {
115+ // @ts -expect-error
116+ runFriendlyId : env . TRIGGER_RUN_ID ,
117+ // @ts -expect-error
118+ snapshotFriendlyId : env . TRIGGER_SNAPSHOT_ID ,
119+ httpClient : this . httpClient ,
120+ logger : this . logger ,
121+ heartbeatIntervalSeconds : this . heartbeatIntervalSeconds ,
152122 } ) ;
153123
154124 process . on ( "SIGTERM" , async ( ) => {
@@ -429,6 +399,8 @@ class ManagedRunController {
429399
430400 try {
431401 this . updateRunPhase ( run , snapshot ) ;
402+
403+ this . runHeartbeat . updateSnapshotId ( snapshot . friendlyId ) ;
432404 this . snapshotPoller . updateSnapshotId ( snapshot . friendlyId ) ;
433405 } catch ( error ) {
434406 this . sendDebugLog ( {
0 commit comments