use of com.netflix.conductor.core.events.queue.Message in project conductor by Netflix.
the class SimpleEventProcessor method executeEvent.
/**
* Executes all the actions configured on all the event handlers triggered by the {@link Message} on the queue
* If any of the actions on an event handler fails due to a transient failure, the execution is not persisted such that it can be retried
*
* @return a list of {@link EventExecution} that failed due to transient failures.
*/
protected List<EventExecution> executeEvent(String event, Message msg) throws Exception {
List<EventHandler> eventHandlerList = metadataService.getEventHandlersForEvent(event, true);
Object payloadObject = getPayloadObject(msg.getPayload());
List<EventExecution> transientFailures = new ArrayList<>();
for (EventHandler eventHandler : eventHandlerList) {
String condition = eventHandler.getCondition();
if (StringUtils.isNotEmpty(condition)) {
logger.debug("Checking condition: {} for event: {}", condition, event);
Boolean success = ScriptEvaluator.evalBool(condition, jsonUtils.expand(payloadObject));
if (!success) {
String id = msg.getId() + "_" + 0;
EventExecution eventExecution = new EventExecution(id, msg.getId());
eventExecution.setCreated(System.currentTimeMillis());
eventExecution.setEvent(eventHandler.getEvent());
eventExecution.setName(eventHandler.getName());
eventExecution.setStatus(Status.SKIPPED);
eventExecution.getOutput().put("msg", msg.getPayload());
eventExecution.getOutput().put("condition", condition);
executionService.addEventExecution(eventExecution);
logger.debug("Condition: {} not successful for event: {} with payload: {}", condition, eventHandler.getEvent(), msg.getPayload());
continue;
}
}
CompletableFuture<List<EventExecution>> future = executeActionsForEventHandler(eventHandler, msg);
future.whenComplete((result, error) -> result.forEach(eventExecution -> {
if (error != null || eventExecution.getStatus() == Status.IN_PROGRESS) {
transientFailures.add(eventExecution);
} else {
executionService.updateEventExecution(eventExecution);
}
})).get();
}
return processTransientFailures(transientFailures);
}
use of com.netflix.conductor.core.events.queue.Message in project conductor by Netflix.
the class Event method cancel.
@Override
public void cancel(Workflow workflow, Task task, WorkflowExecutor provider) {
Message message = new Message(task.getTaskId(), null, task.getTaskId());
getQueue(workflow, task).ack(Collections.singletonList(message));
}
use of com.netflix.conductor.core.events.queue.Message in project conductor by Netflix.
the class TestElasticSearchRestDAOV6 method shouldAddMessage.
@Test
public void shouldAddMessage() {
String queue = "queue";
Message message1 = new Message(uuid(), "payload1", null);
Message message2 = new Message(uuid(), "payload2", null);
indexDAO.addMessage(queue, message1);
indexDAO.addMessage(queue, message2);
List<Message> indexedMessages = tryFindResults(() -> indexDAO.getMessages(queue), 2);
assertEquals(2, indexedMessages.size());
assertTrue("Not all messages was indexed", indexedMessages.containsAll(Arrays.asList(message1, message2)));
}
use of com.netflix.conductor.core.events.queue.Message in project conductor by Netflix.
the class AMQPObservableQueue method asMessage.
private static Message asMessage(AMQPSettings settings, GetResponse response) throws Exception {
if (response == null) {
return null;
}
final Message message = new Message();
message.setId(response.getProps().getMessageId());
message.setPayload(new String(response.getBody(), settings.getContentEncoding()));
message.setReceipt(String.valueOf(response.getEnvelope().getDeliveryTag()));
return message;
}
use of com.netflix.conductor.core.events.queue.Message in project conductor by Netflix.
the class AMQPObservableQueue method observe.
@Override
public Observable<Message> observe() {
receiveMessages();
Observable.OnSubscribe<Message> onSubscribe = subscriber -> {
Observable<Long> interval = Observable.interval(pollTimeInMS, TimeUnit.MILLISECONDS);
interval.flatMap((Long x) -> {
List<Message> available = new LinkedList<>();
messages.drainTo(available);
if (!available.isEmpty()) {
AtomicInteger count = new AtomicInteger(0);
StringBuilder buffer = new StringBuilder();
available.forEach(msg -> {
buffer.append(msg.getId()).append("=").append(msg.getPayload());
count.incrementAndGet();
if (count.get() < available.size()) {
buffer.append(",");
}
});
logger.info(String.format("Batch from %s to conductor is %s", settings.getQueueOrExchangeName(), buffer.toString()));
}
return Observable.from(available);
}).subscribe(subscriber::onNext, subscriber::onError);
};
return Observable.create(onSubscribe);
}
Aggregations