aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io/trygvis/queue/JpaAsyncService.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/io/trygvis/queue/JpaAsyncService.java')
-rwxr-xr-xsrc/main/java/io/trygvis/queue/JpaAsyncService.java37
1 files changed, 34 insertions, 3 deletions
diff --git a/src/main/java/io/trygvis/queue/JpaAsyncService.java b/src/main/java/io/trygvis/queue/JpaAsyncService.java
index 95d5ef3..e715ac7 100755
--- a/src/main/java/io/trygvis/queue/JpaAsyncService.java
+++ b/src/main/java/io/trygvis/queue/JpaAsyncService.java
@@ -101,6 +101,11 @@ public class JpaAsyncService implements AsyncService<JpaAsyncService.JpaQueueRef
return new JpaExecutionRef(task);
}
+ @Transactional(readOnly = true)
+ public JpaExecutionRef update(JpaExecutionRef ref) {
+ return new JpaExecutionRef(taskRepository.findOne(ref.task.getId()));
+ }
+
public static class JpaQueueRef implements AsyncService.QueueRef {
public final Queue queue;
@@ -122,6 +127,26 @@ public class JpaAsyncService implements AsyncService<JpaAsyncService.JpaQueueRef
this.task = task;
}
+ public List<String> getArguments() {
+ return Arrays.asList(task.getArguments());
+ }
+
+ public Date getScheduled() {
+ return task.getScheduled();
+ }
+
+ public Date getLastRun() {
+ return task.getLastRun();
+ }
+
+ public Date getCompleted() {
+ return task.getCompleted();
+ }
+
+ public boolean isDone() {
+ return task.isDone();
+ }
+
public String toString() {
return "JpaExecutionRef{" +
"task=" + task +
@@ -129,6 +154,12 @@ public class JpaAsyncService implements AsyncService<JpaAsyncService.JpaQueueRef
}
}
+ private static class TaskFailureException extends RuntimeException {
+ public TaskFailureException(Exception e) {
+ super(e);
+ }
+ }
+
private class CheckTimerTask implements Runnable {
private final AsyncCallable callable;
private final JpaQueueRef queueRef;
@@ -149,12 +180,12 @@ public class JpaAsyncService implements AsyncService<JpaAsyncService.JpaQueueRef
for (final Task task : tasks) {
try {
executeTask(task);
- } catch (TransactionException e) {
+ } catch (TransactionException | TaskFailureException e) {
log.warn("Task execution failed", e);
}
}
} catch (Exception e) {
- log.warn("Error while execution tasks.", e);
+ log.warn("Error while executing tasks.", e);
}
}
@@ -177,7 +208,7 @@ public class JpaAsyncService implements AsyncService<JpaAsyncService.JpaQueueRef
task.registerComplete(completed);
taskRepository.save(task);
} catch (Exception e) {
- throw new RuntimeException("Error while executing callback", e);
+ throw new TaskFailureException(e);
}
}
});