@@ -390,25 +390,33 @@ export const purgeDefaultKeyValueStore = async () => {
390390 await Promise . all ( deletePromises ) ;
391391} ;
392392
393- export const outputJobLog = async ( job : ActorRun | Build , timeout ?: number ) => {
393+ export const outputJobLog = async ( {
394+ job,
395+ timeoutMillis,
396+ apifyClient,
397+ } : {
398+ job : ActorRun | Build ;
399+ timeoutMillis ?: number ;
400+ apifyClient ?: ApifyClient ;
401+ } ) => {
394402 const { id : logId , status } = job ;
395- const apifyClient = new ApifyClient ( { baseUrl : process . env . APIFY_CLIENT_BASE_URL } ) ;
403+ const client = apifyClient || new ApifyClient ( { baseUrl : process . env . APIFY_CLIENT_BASE_URL } ) ;
396404
397405 // In case job was already done just output log
398406 if ( ACTOR_JOB_TERMINAL_STATUSES . includes ( status as never ) ) {
399407 if ( process . env . APIFY_NO_LOGS_IN_TESTS ) {
400408 return ;
401409 }
402410
403- const log = await apifyClient . log ( logId ) . get ( ) ;
411+ const log = await client . log ( logId ) . get ( ) ;
404412 process . stderr . write ( log ! ) ;
405413 return ;
406414 }
407415
408416 // In other case stream it to stderr
409417 // eslint-disable-next-line no-async-promise-executor
410418 return new Promise < 'no-logs' | 'finished' | 'timeouts' > ( async ( resolve ) => {
411- const stream = await apifyClient . log ( logId ) . stream ( ) ;
419+ const stream = await client . log ( logId ) . stream ( ) ;
412420
413421 if ( ! stream ) {
414422 resolve ( 'no-logs' ) ;
@@ -435,11 +443,11 @@ export const outputJobLog = async (job: ActorRun | Build, timeout?: number) => {
435443 }
436444 } ) ;
437445
438- if ( timeout ) {
446+ if ( timeoutMillis ) {
439447 nodeTimeout = setTimeout ( ( ) => {
440448 stream . destroy ( ) ;
441449 resolve ( 'timeouts' ) ;
442- } , timeout ) ;
450+ } , timeoutMillis ) ;
443451 }
444452 } ) ;
445453} ;
0 commit comments