Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions src/main/java/net/greghaines/jesque/meta/QueueInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
*/
package net.greghaines.jesque.meta;

import java.io.Serializable;
import java.util.List;

import net.greghaines.jesque.Job;
import net.greghaines.jesque.utils.JesqueUtils;

import java.io.Serializable;
import java.util.List;

/**
* Information about the current state of a queue.
*
Expand All @@ -33,6 +33,7 @@ public class QueueInfo implements Comparable<QueueInfo>, Serializable {
private String name;
private Long size;
private List<Job> jobs;
private Boolean delayed;

/**
* @return the name of the queue
Expand Down Expand Up @@ -76,6 +77,20 @@ public void setJobs(final List<Job> jobs) {
this.jobs = jobs;
}

/**
* @return whether this queue is a delayed queue
*/
public Boolean isDelayed() {
return this.delayed;
}

/**
* @param delayed whether this queue is a delayed queue
*/
public void setDelayed(final Boolean delayed) {
this.delayed = delayed;
}

/**
* {@inheritDoc}
*/
Expand All @@ -94,6 +109,7 @@ public int hashCode() {
result = prime * result + ((this.jobs == null) ? 0 : this.jobs.hashCode());
result = prime * result + ((this.name == null) ? 0 : this.name.hashCode());
result = prime * result + ((this.size == null) ? 0 : this.size.hashCode());
result = prime * result + ((this.delayed == null) ? 0 : this.delayed.hashCode());
return result;
}

Expand All @@ -109,7 +125,8 @@ public boolean equals(final Object obj) {
final QueueInfo other = (QueueInfo) obj;
equal = (JesqueUtils.nullSafeEquals(this.jobs, other.jobs)
&& JesqueUtils.nullSafeEquals(this.name, other.name)
&& JesqueUtils.nullSafeEquals(this.size, other.size));
&& JesqueUtils.nullSafeEquals(this.size, other.size)
&& JesqueUtils.nullSafeEquals(this.delayed, other.delayed));
}
return equal;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ public List<QueueInfo> doWork(final Jedis jedis) throws Exception {
final QueueInfo queueInfo = new QueueInfo();
queueInfo.setName(queueName);
queueInfo.setSize(size(jedis, queueName));
queueInfo.setDelayed(delayed(jedis, queueName));
queueInfos.add(queueInfo);
}
Collections.sort(queueInfos);
Expand All @@ -159,6 +160,7 @@ public QueueInfo doWork(final Jedis jedis) throws Exception {
final QueueInfo queueInfo = new QueueInfo();
queueInfo.setName(name);
queueInfo.setSize(size(jedis, name));
queueInfo.setDelayed(delayed(jedis, name));
final Collection<String> payloads = paylods(jedis, name, jobOffset, jobCount);
final List<Job> jobs = new ArrayList<Job>(payloads.size());
for (final String payload : payloads) {
Expand All @@ -170,6 +172,11 @@ public QueueInfo doWork(final Jedis jedis) throws Exception {
});
}

private boolean delayed(Jedis jedis, String queueName) {
final String key = key(QUEUE, queueName);
return JedisUtils.isDelayedQueue(jedis, key);
}

/**
* {@inheritDoc}
*/
Expand Down
3 changes: 3 additions & 0 deletions src/test/java/net/greghaines/jesque/meta/TestQueueInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ public void testProperties() {
final List<Job> jobs = Arrays.asList(new Job());
qInfo.setJobs(jobs);
Assert.assertEquals(jobs, qInfo.getJobs());
final boolean delayed = true;
qInfo.setDelayed(delayed);
Assert.assertEquals(delayed, qInfo.isDelayed());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public void testGetQueueInfos() {
oneOf(jedis).smembers(QUEUES_KEY); will(returnValue(queueCountMap.keySet()));
for (final Entry<String,String> e : queueTypeMap.entrySet()) {
final String queueKey = "resque:queue:" + e.getKey();
oneOf(jedis).type(queueKey); will(returnValue(e.getValue()));
exactly(2).of(jedis).type(queueKey); will(returnValue(e.getValue()));
if (KeyType.ZSET.toString().equals(e.getValue())) {
oneOf(jedis).zcard(queueKey); will(returnValue(queueCountMap.get(e.getKey())));
} else {
Expand Down Expand Up @@ -194,7 +194,7 @@ public void testGetQueueInfo_List() throws JsonProcessingException {
payloads.add(ObjectMapperFactory.get().writeValueAsString(new Job("bar")));
this.mockCtx.checking(new Expectations(){{
oneOf(pool).getResource(); will(returnValue(jedis));
exactly(2).of(jedis).type(queueKey); will(returnValue(KeyType.LIST.toString()));
exactly(3).of(jedis).type(queueKey); will(returnValue(KeyType.LIST.toString()));
oneOf(jedis).llen(queueKey); will(returnValue(size));
oneOf(jedis).lrange(queueKey, jobOffset, jobOffset + jobCount - 1); will(returnValue(payloads));
oneOf(jedis).close();
Expand All @@ -220,7 +220,7 @@ public void testGetQueueInfo_ZSet() throws JsonProcessingException {
payloads.add(ObjectMapperFactory.get().writeValueAsString(new Job("bar")));
this.mockCtx.checking(new Expectations(){{
oneOf(pool).getResource(); will(returnValue(jedis));
exactly(2).of(jedis).type(queueKey); will(returnValue(KeyType.ZSET.toString()));
exactly(3).of(jedis).type(queueKey); will(returnValue(KeyType.ZSET.toString()));
oneOf(jedis).zcard(queueKey); will(returnValue(size));
oneOf(jedis).zrange(queueKey, jobOffset, jobOffset + jobCount - 1); will(returnValue(payloads));
oneOf(jedis).close();
Expand Down