// Update consecutive failures, and check for limit
consecFails++;
// Fire Local Event
ServiceMessage message = new ServiceMessage(jobId, ServiceMessageType.LOCAL_TASKFAILED);
ServiceEventsSupport.fireServiceEvent(message);
if (consecFails > CONSECUTIVE_FAILURES_THRESHOLD) {
try {
// If we are above consecutive failure threshold,
// slow down result production
Thread.sleep(500 * (consecFails - CONSECUTIVE_FAILURES_THRESHOLD));
} catch (InterruptedException ie) {
log.warn("Interrupted", ie);
}
}
} finally {
// Set Execution Time
long duration = System.currentTimeMillis() - start;
taskResult.setExecutionTime(duration);
// If result is execution time aware, set the execution time
if (taskResult.getResult() instanceof ExecutionTimeAware) {
((ExecutionTimeAware) taskResult.getResult()).setExecutionTime(duration);
}
log.debug("[TaskExecutor] Sending Result for Task " + taskId + " | Duration : " + duration);
// Send the result to ResultQueue
sendResult(taskResult);
// Fire Local Event
ServiceMessage doneMessage = new ServiceMessage(jobId, ServiceMessageType.LOCAL_TASKDONE);
ServiceEventsSupport.fireServiceEvent(doneMessage);
// Fire Local Event
ServiceMessage timeMessage = new ServiceMessage(String.valueOf(duration),
ServiceMessageType.LOCAL_TASKEXEC);
ServiceEventsSupport.fireServiceEvent(timeMessage);
}
}