1- import { HeartbeatService , RunExecutionData } from "@trigger.dev/core/v3" ;
1+ import { IntervalService } from "@trigger.dev/core/v3" ;
22import { WorkloadHttpClient } from "@trigger.dev/core/v3/runEngineWorker" ;
33import { RunLogger } from "./logger.js" ;
44
@@ -17,7 +17,7 @@ export class RunExecutionHeartbeat {
1717 private readonly httpClient : WorkloadHttpClient ;
1818 private readonly logger : RunLogger ;
1919 private readonly heartbeatIntervalMs : number ;
20- private readonly heartbeat : HeartbeatService ;
20+ private readonly heartbeat : IntervalService ;
2121
2222 constructor ( opts : RunExecutionHeartbeatOptions ) {
2323 this . runFriendlyId = opts . runFriendlyId ;
@@ -36,8 +36,8 @@ export class RunExecutionHeartbeat {
3636 } ,
3737 } ) ;
3838
39- this . heartbeat = new HeartbeatService ( {
40- heartbeat : async ( ) => {
39+ this . heartbeat = new IntervalService ( {
40+ onInterval : async ( ) => {
4141 this . logger . sendDebugLog ( {
4242 runId : this . runFriendlyId ,
4343 message : "heartbeat: started" ,
@@ -90,108 +90,3 @@ export class RunExecutionHeartbeat {
9090 this . heartbeat . stop ( ) ;
9191 }
9292}
93-
94- type RunExecutionSnapshotPollerOptions = {
95- runFriendlyId : string ;
96- snapshotFriendlyId : string ;
97- httpClient : WorkloadHttpClient ;
98- logger : RunLogger ;
99- snapshotPollIntervalSeconds : number ;
100- handleSnapshotChange : ( execution : RunExecutionData ) => Promise < void > ;
101- } ;
102-
103- class RunExecutionSnapshotPoller {
104- private readonly logger : RunLogger ;
105- private readonly poller : HeartbeatService ;
106- private readonly httpClient : WorkloadHttpClient ;
107-
108- private readonly runFriendlyId : string ;
109- private readonly snapshotFriendlyId : string ;
110-
111- private readonly handleSnapshotChange : ( execution : RunExecutionData ) => Promise < void > ;
112-
113- constructor ( opts : RunExecutionSnapshotPollerOptions ) {
114- this . logger = opts . logger ;
115- this . httpClient = opts . httpClient ;
116-
117- this . runFriendlyId = opts . runFriendlyId ;
118- this . snapshotFriendlyId = opts . snapshotFriendlyId ;
119-
120- this . handleSnapshotChange = opts . handleSnapshotChange ;
121-
122- this . poller = new HeartbeatService ( {
123- heartbeat : async ( ) => {
124- if ( ! this . runFriendlyId ) {
125- this . logger . sendDebugLog ( {
126- runId : this . runFriendlyId ,
127- message : "Skipping snapshot poll, no run ID" ,
128- } ) ;
129- return ;
130- }
131-
132- this . logger . sendDebugLog ( {
133- runId : this . runFriendlyId ,
134- message : "Polling for latest snapshot" ,
135- } ) ;
136-
137- this . logger . sendDebugLog ( {
138- runId : this . runFriendlyId ,
139- message : `snapshot poll: started` ,
140- properties : {
141- snapshotId : this . snapshotFriendlyId ,
142- } ,
143- } ) ;
144-
145- const response = await this . httpClient . getRunExecutionData ( this . runFriendlyId ) ;
146-
147- if ( ! response . success ) {
148- this . logger . sendDebugLog ( {
149- runId : this . runFriendlyId ,
150- message : "Snapshot poll failed" ,
151- properties : {
152- error : response . error ,
153- } ,
154- } ) ;
155-
156- this . logger . sendDebugLog ( {
157- runId : this . runFriendlyId ,
158- message : `snapshot poll: failed` ,
159- properties : {
160- snapshotId : this . snapshotFriendlyId ,
161- error : response . error ,
162- } ,
163- } ) ;
164-
165- return ;
166- }
167-
168- await this . handleSnapshotChange ( response . data . execution ) ;
169- } ,
170- intervalMs : opts . snapshotPollIntervalSeconds * 1000 ,
171- leadingEdge : false ,
172- onError : async ( error ) => {
173- this . logger . sendDebugLog ( {
174- runId : this . runFriendlyId ,
175- message : "Failed to poll for snapshot" ,
176- properties : { error : error instanceof Error ? error . message : String ( error ) } ,
177- } ) ;
178- } ,
179- } ) ;
180- }
181-
182- resetCurrentInterval ( ) {
183- this . poller . resetCurrentInterval ( ) ;
184- }
185-
186- updateInterval ( intervalMs : number ) {
187- this . poller . updateInterval ( intervalMs ) ;
188- }
189-
190- start ( ) {
191- this . poller . start ( ) ;
192- }
193-
194- stop ( ) {
195- this . poller . stop ( ) ;
196- }
197- }
0 commit comments