use of com.netflix.conductor.core.events.queue.ObservableQueue in project conductor by Netflix.
the class TestQueueManager method test.
@Test
public void test() throws Exception {
Map<Status, ObservableQueue> queues = new HashMap<>();
queues.put(Status.COMPLETED, queue);
QueueManager qm = new QueueManager(queues, es, objectMapper);
qm.updateByTaskRefName("v_0", "t0", new HashMap<>(), Status.COMPLETED);
Uninterruptibles.sleepUninterruptibly(1_000, TimeUnit.MILLISECONDS);
assertTrue(updatedTasks.stream().anyMatch(task -> task.getTaskId().equals("t0")));
}
use of com.netflix.conductor.core.events.queue.ObservableQueue in project conductor by Netflix.
the class TestQueueManager method testWithTaskId.
@Test
public void testWithTaskId() throws Exception {
Map<Status, ObservableQueue> queues = new HashMap<>();
queues.put(Status.COMPLETED, queue);
QueueManager qm = new QueueManager(queues, es, objectMapper);
qm.updateByTaskId("v_2", "t2", new HashMap<>(), Status.COMPLETED);
Uninterruptibles.sleepUninterruptibly(1_000, TimeUnit.MILLISECONDS);
assertTrue(updatedTasks.stream().anyMatch(task -> task.getTaskId().equals("t2")));
}
use of com.netflix.conductor.core.events.queue.ObservableQueue in project conductor by Netflix.
the class QueueManager method size.
public Map<String, Long> size() {
Map<String, Long> size = new HashMap<>();
queues.entrySet().forEach(e -> {
ObservableQueue queue = e.getValue();
size.put(queue.getName(), queue.size());
});
return size;
}
use of com.netflix.conductor.core.events.queue.ObservableQueue in project conductor by Netflix.
the class QueueManager method queues.
public Map<Status, String> queues() {
Map<Status, String> size = new HashMap<>();
queues.entrySet().forEach(e -> {
ObservableQueue queue = e.getValue();
size.put(e.getKey(), queue.getURI());
});
return size;
}
use of com.netflix.conductor.core.events.queue.ObservableQueue in project conductor by Netflix.
the class QueueManager method startMonitor.
private void startMonitor(Status status, ObservableQueue queue) {
queue.observe().subscribe((Message msg) -> {
try {
logger.debug("Got message {}", msg.getPayload());
String payload = msg.getPayload();
JsonNode payloadJSON = objectMapper.readTree(payload);
String externalId = getValue("externalId", payloadJSON);
if (externalId == null || "".equals(externalId)) {
logger.error("No external Id found in the payload {}", payload);
queue.ack(Collections.singletonList(msg));
return;
}
JsonNode json = objectMapper.readTree(externalId);
String workflowId = getValue("workflowId", json);
String taskRefName = getValue("taskRefName", json);
String taskId = getValue("taskId", json);
if (workflowId == null || "".equals(workflowId)) {
// This is a bad message, we cannot process it
logger.error("No workflow id found in the message. {}", payload);
queue.ack(Collections.singletonList(msg));
return;
}
Workflow workflow = executionService.getExecutionStatus(workflowId, true);
Optional<Task> taskOptional;
if (StringUtils.isNotEmpty(taskId)) {
taskOptional = workflow.getTasks().stream().filter(task -> !task.getStatus().isTerminal() && task.getTaskId().equals(taskId)).findFirst();
} else if (StringUtils.isEmpty(taskRefName)) {
logger.error("No taskRefName found in the message. If there is only one WAIT task, will mark it as completed. {}", payload);
taskOptional = workflow.getTasks().stream().filter(task -> !task.getStatus().isTerminal() && task.getTaskType().equals(Wait.NAME)).findFirst();
} else {
taskOptional = workflow.getTasks().stream().filter(task -> !task.getStatus().isTerminal() && task.getReferenceTaskName().equals(taskRefName)).findFirst();
}
if (!taskOptional.isPresent()) {
logger.error("No matching tasks found to be marked as completed for workflow {}, taskRefName {}, taskId {}", workflowId, taskRefName, taskId);
queue.ack(Collections.singletonList(msg));
return;
}
Task task = taskOptional.get();
task.setStatus(status);
task.getOutputData().putAll(objectMapper.convertValue(payloadJSON, _mapType));
executionService.updateTask(task);
List<String> failures = queue.ack(Collections.singletonList(msg));
if (!failures.isEmpty()) {
logger.error("Not able to ack the messages {}", failures.toString());
}
} catch (JsonParseException e) {
logger.error("Bad message? : {} ", msg, e);
queue.ack(Collections.singletonList(msg));
} catch (ApplicationException e) {
if (e.getCode().equals(Code.NOT_FOUND)) {
logger.error("Workflow ID specified is not valid for this environment");
queue.ack(Collections.singletonList(msg));
}
logger.error("Error processing message: {}", msg, e);
} catch (Exception e) {
logger.error("Error processing message: {}", msg, e);
}
}, (Throwable t) -> {
logger.error(t.getMessage(), t);
});
logger.info("QueueListener::STARTED...listening for " + queue.getName());
}
Aggregations