public TaskStatus pollTaskStatus ( String taskId , Map < String , String > reqHeaders ) { CloseableHttpResponse resp = null ; String url = format ( "%s/%s/status" , format ( overlordUrl , overlordHost , overlordPort ) , taskId ) ; try { resp = get ( url , reqHeaders ) ; //TODO: Check for nulls in the following. JSONObject respJson = new JSONObject ( IOUtils . toString ( resp . getEntity ( ) . getContent ( ) ) ) ; JSONObject status = respJson . optJSONObject ( "status" ) ; if ( status != null && null != status . getString ( "status" ) ) { switch ( status . getString ( "status" ) ) { case "SUCCESS" : return TaskStatus . SUCCESS ; case "RUNNING" : return TaskStatus . RUNNING ; default : return TaskStatus . FAILED ; } } } catch ( IOException ex ) { log . error ( "Error polling for task status {}" , ExceptionUtils . getStackTrace ( ex ) ) ; } finally { returnClient ( resp ) ; } // Happens when result looks like {"task":"null"} which has no status(because such a task itself does not exist) return TaskStatus . UNKNOWN ; }
Poll for task s status for tasks fired with 0 wait time .