@ Override public void run ( ) { try { log . debug ( "About to check status for jobId {}" , jobId ) ; final JobStatus < T > jobStatus ; if ( tokenProxy != null ) { jobStatus = jobService . getJobStatus ( tokenProxy , jobId ) ; } else { jobStatus = jobService . getJobStatus ( jobId ) ; } final Status jobStatusStatus = jobStatus . getStatus ( ) ; if ( jobStatusStatus == Status . FINISHED || jobStatusStatus == Status . FAILED ) { for ( final Action < T > action : jobStatus . getActions ( ) ) { final Status status = action . getStatus ( ) ; if ( status == Status . FINISHED ) { log . debug ( "Found a finished action, calling callback" ) ; callback . success ( action . getResult ( ) ) ; } else if ( status == Status . FAILED ) { log . debug ( "Found a failed action, calling callback" ) ; for ( final HodError error : action . getErrors ( ) ) { log . debug ( "Error callback called with: {}" , error ) ; callback . error ( error . getErrorCode ( ) ) ; } } } } else if ( timeout != null && timeout . isBefore ( LocalDateTime . now ( ) ) ) { callback . timeout ( ) ; log . debug ( "Timeout callback called" ) ; } else { log . debug ( "Not finished or failed, retrying" ) ; // we got a status successfully, so reset the counter tries . set ( 0 ) ; executorService . schedule ( this , WAIT_SECONDS , TimeUnit . SECONDS ) ; } } catch ( final HodErrorException e ) { log . error ( "Error retrieving job status for jobId: {}" , jobId ) ; log . error ( "Cause:" , e ) ; if ( DO_NOT_RETRY_CODES . contains ( e . getErrorCode ( ) ) ) { log . error ( "Unrecoverable error, will not retry" ) ; callback . error ( e . getErrorCode ( ) ) ; } else if ( tries . get ( ) >= MAX_TRIES ) { log . error ( "Max retries reached, will not retry" ) ; callback . error ( e . getErrorCode ( ) ) ; } else { log . error ( "Retrying" ) ; tries . incrementAndGet ( ) ; executorService . schedule ( this , WAIT_SECONDS , TimeUnit . SECONDS ) ; } } catch ( final RuntimeException e ) { log . error ( "Error retrieving job status for jobId: {}" , jobId ) ; log . error ( "Cause:" , e ) ; callback . handleException ( e ) ; } }
Checks the status of the job . If the job has not finished the runnable will schedule itself to run again after a short wait