11import { assertExhaustive } from "../../utils.js" ;
22import { clock } from "../clock-api.js" ;
33import { lifecycleHooks } from "../lifecycle-hooks-api.js" ;
4+ import { DebugLogProperties } from "../runEngineWorker/index.js" ;
45import {
56 BatchTaskRunExecutionResult ,
67 CompletedWaitpoint ,
@@ -176,7 +177,10 @@ export class SharedRuntimeManager implements RuntimeManager {
176177 switch ( waitpoint . type ) {
177178 case "RUN" : {
178179 if ( ! waitpoint . completedByTaskRun ) {
179- this . log ( "No completedByTaskRun for RUN waitpoint" , waitpoint ) ;
180+ this . debugLog (
181+ "No completedByTaskRun for RUN waitpoint" ,
182+ this . waitpointForDebugLog ( waitpoint )
183+ ) ;
180184 return null ;
181185 }
182186
@@ -192,7 +196,10 @@ export class SharedRuntimeManager implements RuntimeManager {
192196 }
193197 case "BATCH" : {
194198 if ( ! waitpoint . completedByBatch ) {
195- this . log ( "No completedByBatch for BATCH waitpoint" , waitpoint ) ;
199+ this . debugLog (
200+ "No completedByBatch for BATCH waitpoint" ,
201+ this . waitpointForDebugLog ( waitpoint )
202+ ) ;
196203 return null ;
197204 }
198205
@@ -213,18 +220,19 @@ export class SharedRuntimeManager implements RuntimeManager {
213220 }
214221
215222 private resolveWaitpoint ( waitpoint : CompletedWaitpoint , resolverId ?: ResolverId | null ) : void {
223+ // This is spammy, don't make this a debug log
216224 this . log ( "resolveWaitpoint" , waitpoint ) ;
217225
218226 if ( waitpoint . type === "BATCH" ) {
219227 // We currently ignore these, they're not required to resume after a batch completes
220- this . log ( "Ignoring BATCH waitpoint" , waitpoint ) ;
228+ this . debugLog ( "Ignoring BATCH waitpoint" , this . waitpointForDebugLog ( waitpoint ) ) ;
221229 return ;
222230 }
223231
224232 resolverId = resolverId ?? this . resolverIdFromWaitpoint ( waitpoint ) ;
225233
226234 if ( ! resolverId ) {
227- this . log ( "No resolverId for waitpoint" , { ... this . status , ... waitpoint } ) ;
235+ this . debugLog ( "No resolverId for waitpoint" , this . waitpointForDebugLog ( waitpoint ) ) ;
228236
229237 // No need to store the waitpoint, we'll never be able to resolve it
230238 return ;
@@ -233,7 +241,7 @@ export class SharedRuntimeManager implements RuntimeManager {
233241 const resolve = this . resolversById . get ( resolverId ) ;
234242
235243 if ( ! resolve ) {
236- this . log ( "No resolver found for resolverId" , { ...this . status , resolverId } ) ;
244+ this . debugLog ( "No resolver found for resolverId" , { ...this . status , resolverId } ) ;
237245
238246 // Store the waitpoint for later if we can't find a resolver
239247 this . waitpointsByResolverId . set ( resolverId , waitpoint ) ;
@@ -280,6 +288,42 @@ export class SharedRuntimeManager implements RuntimeManager {
280288 }
281289 }
282290
291+ private waitpointForDebugLog ( waitpoint : CompletedWaitpoint ) : DebugLogProperties {
292+ const {
293+ completedByTaskRun,
294+ completedByBatch,
295+ completedAfter,
296+ completedAt,
297+ output,
298+ id,
299+ ...rest
300+ } = waitpoint ;
301+
302+ return {
303+ ...rest ,
304+ waitpointId : id ,
305+ output : output ?. slice ( 0 , 100 ) ,
306+ completedByTaskRunId : completedByTaskRun ?. id ,
307+ completedByTaskRunBatchId : completedByTaskRun ?. batch ?. id ,
308+ completedByBatchId : completedByBatch ?. id ,
309+ completedAfter : completedAfter ?. toISOString ( ) ,
310+ completedAt : completedAt ?. toISOString ( ) ,
311+ } ;
312+ }
313+
314+ private debugLog ( message : string , properties ?: DebugLogProperties ) {
315+ const status = this . status ;
316+
317+ if ( this . showLogs ) {
318+ console . log ( `[${ new Date ( ) . toISOString ( ) } ] ${ message } ` , { ...status , ...properties } ) ;
319+ }
320+
321+ this . ipc . send ( "SEND_DEBUG_LOG" , {
322+ message,
323+ properties : { ...status , ...properties } ,
324+ } ) ;
325+ }
326+
283327 private log ( message : string , ...args : any [ ] ) {
284328 if ( ! this . showLogs ) return ;
285329 console . log ( `[${ new Date ( ) . toISOString ( ) } ] ${ message } ` , args ) ;
0 commit comments