public long getCount() { return PoolUtils.doWorkInPoolNicely( this.jedisPool, new PoolWork<Jedis, Long>() { public Long doWork(final Jedis jedis) throws Exception { return jedis.llen(key(FAILED)); } }); }
public void clear() { PoolUtils.doWorkInPoolNicely( this.jedisPool, new PoolWork<Jedis, Void>() { public Void doWork(final Jedis jedis) throws Exception { jedis.del(key(FAILED)); return null; } }); }
public void remove(final long index) { PoolUtils.doWorkInPoolNicely( this.jedisPool, new PoolWork<Jedis, Void>() { public Void doWork(final Jedis jedis) throws Exception { final String failedKey = key(FAILED); final String randId = Integer.toString(new Random().nextInt()); jedis.lset(failedKey, index, randId); jedis.lrem(failedKey, 1, randId); return null; } }); }
public List<JobFailure> getFailures(final long offset, final long count) { return PoolUtils.doWorkInPoolNicely( this.jedisPool, new PoolWork<Jedis, List<JobFailure>>() { public List<JobFailure> doWork(final Jedis jedis) throws Exception { final List<String> payloads = jedis.lrange(key(FAILED), offset, offset + count - 1); final List<JobFailure> failures = new ArrayList<JobFailure>(payloads.size()); for (final String payload : payloads) { failures.add(ObjectMapperFactory.get().readValue(payload, JobFailure.class)); } return failures; } }); }
public Date requeue(final long index) { final List<JobFailure> failures = getFailures(index, 1); return (failures.isEmpty()) ? null : PoolUtils.doWorkInPoolNicely( this.jedisPool, new PoolWork<Jedis, Date>() { public Date doWork(final Jedis jedis) throws Exception { final Date retriedAt = new Date(); final JobFailure failure = failures.get(0); failure.setRetriedAt(retriedAt); jedis.lset( key(FAILED), (int) index, ObjectMapperFactory.get().writeValueAsString(failure)); enqueue(jedis, failure.getQueue(), failure.getPayload()); return retriedAt; } }); }