@@ -103,6 +103,14 @@ export function getPendingCronRunLogWriteCountForTests() {
103103 return writesByPath . size ;
104104}
105105
106+ async function drainPendingWrite ( filePath : string ) : Promise < void > {
107+ const resolved = path . resolve ( filePath ) ;
108+ const pending = writesByPath . get ( resolved ) ;
109+ if ( pending ) {
110+ await pending . catch ( ( ) => undefined ) ;
111+ }
112+ }
113+
106114async function pruneIfNeeded ( filePath : string , opts : { maxBytes : number ; keepLines : number } ) {
107115 const stat = await fs . stat ( filePath ) . catch ( ( ) => null ) ;
108116 if ( ! stat || stat . size <= opts . maxBytes ) {
@@ -152,6 +160,7 @@ export async function readCronRunLogEntries(
152160 filePath : string ,
153161 opts ?: { limit ?: number ; jobId ?: string } ,
154162) : Promise < CronRunLogEntry [ ] > {
163+ await drainPendingWrite ( filePath ) ;
155164 const limit = Math . max ( 1 , Math . min ( 5000 , Math . floor ( opts ?. limit ?? 200 ) ) ) ;
156165 const page = await readCronRunLogEntriesPage ( filePath , {
157166 jobId : opts ?. jobId ,
@@ -334,6 +343,7 @@ export async function readCronRunLogEntriesPage(
334343 filePath : string ,
335344 opts ?: ReadCronRunLogPageOptions ,
336345) : Promise < CronRunLogPageResult > {
346+ await drainPendingWrite ( filePath ) ;
337347 const limit = Math . max ( 1 , Math . min ( 200 , Math . floor ( opts ?. limit ?? 50 ) ) ) ;
338348 const raw = await fs . readFile ( path . resolve ( filePath ) , "utf-8" ) . catch ( ( ) => "" ) ;
339349 const statuses = normalizeRunStatuses ( opts ) ;
@@ -388,6 +398,7 @@ export async function readCronRunLogEntriesPageAll(
388398 nextOffset : null ,
389399 } ;
390400 }
401+ await Promise . all ( jsonlFiles . map ( ( f ) => drainPendingWrite ( f ) ) ) ;
391402 const chunks = await Promise . all (
392403 jsonlFiles . map ( async ( filePath ) => {
393404 const raw = await fs . readFile ( filePath , "utf-8" ) . catch ( ( ) => "" ) ;
0 commit comments