aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io/trygvis/queue
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2013-04-20 18:10:20 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2013-04-20 18:10:20 +0200
commit74a3da1853eeb2e853d17d8d8527404248b209d3 (patch)
tree6bffb7a891034e5141f0f7dc4b04d54d9472310f /src/main/java/io/trygvis/queue
parenta03d5154456587fc7920e632f083cc5f1e4318a9 (diff)
downloadquartz-based-queue-74a3da1853eeb2e853d17d8d8527404248b209d3.tar.gz
quartz-based-queue-74a3da1853eeb2e853d17d8d8527404248b209d3.tar.bz2
quartz-based-queue-74a3da1853eeb2e853d17d8d8527404248b209d3.tar.xz
quartz-based-queue-74a3da1853eeb2e853d17d8d8527404248b209d3.zip
wip
Diffstat (limited to 'src/main/java/io/trygvis/queue')
-rwxr-xr-xsrc/main/java/io/trygvis/queue/AsyncService.java2
-rw-r--r--src/main/java/io/trygvis/queue/JdbcAsyncService.java60
-rw-r--r--src/main/java/io/trygvis/queue/QueueDao.java12
-rwxr-xr-xsrc/main/java/io/trygvis/queue/Task.java5
-rw-r--r--src/main/java/io/trygvis/queue/TaskDao.java17
5 files changed, 60 insertions, 36 deletions
diff --git a/src/main/java/io/trygvis/queue/AsyncService.java b/src/main/java/io/trygvis/queue/AsyncService.java
index b42b550..41bb75a 100755
--- a/src/main/java/io/trygvis/queue/AsyncService.java
+++ b/src/main/java/io/trygvis/queue/AsyncService.java
@@ -1,6 +1,6 @@
package io.trygvis.queue;
-import org.quartz.*;
+import org.quartz.SchedulerException;
import java.util.List;
diff --git a/src/main/java/io/trygvis/queue/JdbcAsyncService.java b/src/main/java/io/trygvis/queue/JdbcAsyncService.java
index a8f581e..06e7eee 100644
--- a/src/main/java/io/trygvis/queue/JdbcAsyncService.java
+++ b/src/main/java/io/trygvis/queue/JdbcAsyncService.java
@@ -1,19 +1,27 @@
package io.trygvis.queue;
-import org.quartz.*;
-import org.slf4j.*;
-import org.springframework.beans.factory.annotation.*;
-import org.springframework.stereotype.*;
-import org.springframework.transaction.annotation.*;
-import org.springframework.transaction.support.*;
-
-import java.util.*;
-import java.util.concurrent.*;
-
-import static java.util.Arrays.*;
-import static java.util.concurrent.TimeUnit.*;
-import static org.springframework.transaction.annotation.Propagation.*;
-import static org.springframework.transaction.support.TransactionSynchronizationManager.*;
+import org.quartz.SchedulerException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.transaction.support.TransactionSynchronization;
+import org.springframework.transaction.support.TransactionSynchronizationAdapter;
+import org.springframework.transaction.support.TransactionTemplate;
+
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledThreadPoolExecutor;
+
+import static java.lang.System.currentTimeMillis;
+import static java.lang.Thread.sleep;
+import static java.util.Arrays.asList;
+import static java.util.concurrent.TimeUnit.SECONDS;
+import static org.springframework.transaction.annotation.Propagation.REQUIRED;
+import static org.springframework.transaction.support.TransactionSynchronizationManager.registerSynchronization;
@Component
public class JdbcAsyncService implements AsyncService {
@@ -96,12 +104,6 @@ public class JdbcAsyncService implements AsyncService {
long id = taskDao.insert(queue.name, scheduled, arguments.toString());
Task task = new Task(id, queue.name, scheduled, null, 0, null, asList(args));
log.info("Created task = {}", task);
-// queues.get(queue.name).ping();
-// try {
-// Thread.sleep(500);
-// } catch (InterruptedException e) {
-// e.printStackTrace();
-// }
registerSynchronization(new TransactionSynchronizationAdapter() {
public void afterCompletion(int status) {
@@ -114,6 +116,24 @@ public class JdbcAsyncService implements AsyncService {
return task;
}
+ @Transactional
+ public Task await(Task task, long timeout) {
+ final long start = currentTimeMillis();
+ final long end = start + timeout;
+
+ while (currentTimeMillis() < end) {
+ task = update(task);
+
+ try {
+ sleep(100);
+ } catch (InterruptedException e) {
+ // break
+ }
+ }
+
+ return task;
+ }
+
@Transactional(readOnly = true)
public Task update(Task ref) {
return taskDao.findById(ref.id);
diff --git a/src/main/java/io/trygvis/queue/QueueDao.java b/src/main/java/io/trygvis/queue/QueueDao.java
index a3a79ca..63dde2a 100644
--- a/src/main/java/io/trygvis/queue/QueueDao.java
+++ b/src/main/java/io/trygvis/queue/QueueDao.java
@@ -1,12 +1,14 @@
package io.trygvis.queue;
-import org.springframework.beans.factory.annotation.*;
-import org.springframework.jdbc.core.*;
-import org.springframework.stereotype.*;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.jdbc.core.RowMapper;
+import org.springframework.stereotype.Component;
-import java.sql.*;
+import java.sql.ResultSet;
+import java.sql.SQLException;
-import static org.springframework.dao.support.DataAccessUtils.*;
+import static org.springframework.dao.support.DataAccessUtils.singleResult;
@Component
public class QueueDao {
diff --git a/src/main/java/io/trygvis/queue/Task.java b/src/main/java/io/trygvis/queue/Task.java
index 7f64c77..9a2e65b 100755
--- a/src/main/java/io/trygvis/queue/Task.java
+++ b/src/main/java/io/trygvis/queue/Task.java
@@ -1,6 +1,7 @@
package io.trygvis.queue;
-import java.util.*;
+import java.util.Date;
+import java.util.List;
public class Task {
@@ -34,7 +35,7 @@ public class Task {
}
public Task registerComplete(Date completed) {
- return new Task(id, queue, scheduled, lastRun, runCount, new Date(), arguments);
+ return new Task(id, queue, scheduled, lastRun, runCount, completed, arguments);
}
public String toString() {
diff --git a/src/main/java/io/trygvis/queue/TaskDao.java b/src/main/java/io/trygvis/queue/TaskDao.java
index 2bf2145..dac99c7 100644
--- a/src/main/java/io/trygvis/queue/TaskDao.java
+++ b/src/main/java/io/trygvis/queue/TaskDao.java
@@ -1,18 +1,19 @@
package io.trygvis.queue;
-import org.springframework.beans.factory.annotation.*;
-import org.springframework.jdbc.core.*;
-import org.springframework.stereotype.*;
-import org.springframework.transaction.annotation.Propagation;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.jdbc.core.RowMapper;
+import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
-import java.sql.*;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Collections;
import java.util.Date;
-import java.util.*;
+import java.util.List;
-import static java.util.Arrays.*;
+import static java.util.Arrays.asList;
import static org.springframework.transaction.annotation.Propagation.MANDATORY;
-import static org.springframework.transaction.annotation.Propagation.REQUIRED;
@Component
public class TaskDao {