return sqs;
}
@Timeout
public void timeout(javax.ejb.Timer timer) {
Queue queue = getSQS().getQueueByName(TASK_SQS_QUEUE);
Optional<ReceivedMessage> sqsAnswer = queue.receiveSingleMessage();
if (sqsAnswer.isPresent()) {
Object message = sqsAnswer.get().getMessage();
if (message instanceof OneTimeTask) {
LOG.debug("Deserialized message: " + message);
OneTimeTask task = (OneTimeTask) message;
try {
if (task.getTaskTimeout() != null) {
queue.setMessageVisibilityTimeout(sqsAnswer.get(), task.getTaskTimeout());
}
new ExecuteWithRequestContext(task).execute();
queue.deleteMessage(sqsAnswer.get());
} catch (RuntimeException e) {
LOG.warn("Something went wrong and the task has not been executed. Redelivery will occur.", e);
}
} else {
LOG.warn("Trash in SQS: " + TASK_SQS_QUEUE);
LOG.warn("Deserialized message: " + message + " -- removing message from queue!");
queue.deleteMessage(sqsAnswer.get());
}
}
LOG.debug("SQS task queue checked " + TASK_SQS_QUEUE);
}