@Override public boolean awaitCompletion(String queueId, long duration, TimeUnit unit) throws InterruptedException { if (!isStarted()) { return true; } SequenceTracer.start("awaitCompletion on " + (queueId == null ? "all queues" : queueId)); long durationInMs = TimeUnit.MILLISECONDS.convert(duration, unit); long deadline = getTimestampAfter(durationInMs); int pause = (int) Math.min(durationInMs, 500L); log.debug("awaitForCompletion {} ms", durationInMs); do { if (noScheduledOrRunningWork(queueId)) { completionSynchronizer.signalCompletedWork(); SequenceTracer.stop("done"); return true; } completionSynchronizer.waitForCompletedWork(pause); } while (System.currentTimeMillis() < deadline); log.info("awaitCompletion timeout after {} ms", durationInMs); SequenceTracer.destroy("timeout after " + durationInMs + " ms"); return false; }
/** * Called when the worker failed to run successfully even after retrying. * @since 10.1 * @param exception the exception that occurred */ public void workFailed(RuntimeException exception) { EventService service = Framework.getService(EventService.class); EventContext eventContext = new EventContextImpl(null, session != null ? session.getPrincipal() : null); eventContext.setProperties(buildWorkFailureEventProps(exception)); Event event = new EventImpl(WORK_FAILED_EVENT, eventContext); event.setIsCommitEvent(true); service.fireEvent(event); if (exception != null) { String msg = "Work failed after " + getRetryCount() + " " + (getRetryCount() == 1 ? "retry" : "retries") + ", class=" + getClass() + " id=" + getId() + " category=" + getCategory() + " title=" + getTitle(); SequenceTracer.destroy("Work failure " + (completionTime - startTime) + " ms"); // all retries have been done, throw the exception throw new NuxeoException(msg, exception); } }
} catch (RuntimeException e) { SequenceTracer.destroy("failure"); String message = "Exception during " + desc.getName() + " sync listener execution, "; if (event.isBubbleException()) {