@@ -365,25 +365,33 @@ export const purgeDefaultKeyValueStore = async () => {
365365 await Promise . all ( deletePromises ) ;
366366} ;
367367
368- export const outputJobLog = async ( job : ActorRun | Build , timeout ?: number ) => {
368+ export const outputJobLog = async ( {
369+ job,
370+ timeoutMillis,
371+ apifyClient,
372+ } : {
373+ job : ActorRun | Build ;
374+ timeoutMillis ?: number ;
375+ apifyClient ?: ApifyClient ;
376+ } ) => {
369377 const { id : logId , status } = job ;
370- const apifyClient = new ApifyClient ( { baseUrl : process . env . APIFY_CLIENT_BASE_URL } ) ;
378+ const client = apifyClient || new ApifyClient ( { baseUrl : process . env . APIFY_CLIENT_BASE_URL } ) ;
371379
372380 // In case job was already done just output log
373381 if ( ACTOR_JOB_TERMINAL_STATUSES . includes ( status as never ) ) {
374382 if ( process . env . APIFY_NO_LOGS_IN_TESTS ) {
375383 return ;
376384 }
377385
378- const log = await apifyClient . log ( logId ) . get ( ) ;
386+ const log = await client . log ( logId ) . get ( ) ;
379387 process . stderr . write ( log ! ) ;
380388 return ;
381389 }
382390
383391 // In other case stream it to stderr
384392 // eslint-disable-next-line no-async-promise-executor
385393 return new Promise < 'no-logs' | 'finished' | 'timeouts' > ( async ( resolve ) => {
386- const stream = await apifyClient . log ( logId ) . stream ( ) ;
394+ const stream = await client . log ( logId ) . stream ( ) ;
387395
388396 if ( ! stream ) {
389397 resolve ( 'no-logs' ) ;
@@ -410,11 +418,11 @@ export const outputJobLog = async (job: ActorRun | Build, timeout?: number) => {
410418 }
411419 } ) ;
412420
413- if ( timeout ) {
421+ if ( timeoutMillis ) {
414422 nodeTimeout = setTimeout ( ( ) => {
415423 stream . destroy ( ) ;
416424 resolve ( 'timeouts' ) ;
417- } , timeout ) ;
425+ } , timeoutMillis ) ;
418426 }
419427 } ) ;
420428} ;
0 commit comments