Package net.greghaines.jesque.meta

Examples of net.greghaines.jesque.meta.WorkerInfo


            oneOf(jedis).get("resque:worker:" + workerName); will(returnValue(statusPayload));
            oneOf(jedis).get("resque:worker:" + workerName + COLON + STARTED); will(returnValue(startedStr));
            oneOf(jedis).get("resque:stat:failed:" + workerName); will(returnValue(failedStr));
            oneOf(jedis).get("resque:stat:processed:" + workerName); will(returnValue(processedStr));
        }});
        final WorkerInfo workerInfo = this.workerInfoDAO.createWorker(workerName, this.jedis);
        Assert.assertEquals(workerName, workerInfo.getName());
        Assert.assertEquals("123", workerInfo.getPid());
        Assert.assertNotNull(workerInfo.getQueues());
        Assert.assertEquals(3, workerInfo.getQueues().size());
        Assert.assertTrue(workerInfo.getQueues().containsAll(Arrays.asList("bar", "baz", "qux")));
        Assert.assertEquals(WorkerInfo.State.IDLE, workerInfo.getState());
        Assert.assertNull(workerInfo.getStatus());
        Assert.assertEquals(new CompositeDateFormat().parse(startedStr), workerInfo.getStarted());
        Assert.assertEquals((Long)2L, workerInfo.getFailed());
        Assert.assertEquals((Long)6L, workerInfo.getProcessed());
    }
View Full Code Here


            oneOf(jedis).get("resque:worker:" + workerName); will(returnValue(statusPayload));
            oneOf(jedis).get("resque:worker:" + workerName + COLON + STARTED); will(returnValue(startedStr));
            oneOf(jedis).get("resque:stat:failed:" + workerName); will(returnValue(failedStr));
            oneOf(jedis).get("resque:stat:processed:" + workerName); will(returnValue(processedStr));
        }});
        final WorkerInfo workerInfo = this.workerInfoDAO.createWorker(workerName, this.jedis);
        Assert.assertEquals(workerName, workerInfo.getName());
        Assert.assertEquals("123", workerInfo.getPid());
        Assert.assertNotNull(workerInfo.getQueues());
        Assert.assertEquals(3, workerInfo.getQueues().size());
        Assert.assertTrue(workerInfo.getQueues().containsAll(Arrays.asList("bar", "baz", "qux")));
        Assert.assertEquals(WorkerInfo.State.PAUSED, workerInfo.getState());
        Assert.assertNotNull(workerInfo.getStatus());
        Assert.assertTrue(workerInfo.getStatus().isPaused());
        Assert.assertNull(workerInfo.getStarted());
        Assert.assertEquals((Long)0L, workerInfo.getFailed());
        Assert.assertEquals((Long)0L, workerInfo.getProcessed());
    }
View Full Code Here

            oneOf(jedis).get("resque:worker:" + workerName); will(returnValue(statusPayload));
            oneOf(jedis).get("resque:worker:" + workerName + COLON + STARTED); will(returnValue(startedStr));
            oneOf(jedis).get("resque:stat:failed:" + workerName); will(returnValue(failedStr));
            oneOf(jedis).get("resque:stat:processed:" + workerName); will(returnValue(processedStr));
        }});
        final WorkerInfo workerInfo = this.workerInfoDAO.createWorker(workerName, this.jedis);
        Assert.assertEquals(workerName, workerInfo.getName());
        Assert.assertEquals("123", workerInfo.getPid());
        Assert.assertNotNull(workerInfo.getQueues());
        Assert.assertEquals(3, workerInfo.getQueues().size());
        Assert.assertTrue(workerInfo.getQueues().containsAll(Arrays.asList("bar", "baz", "qux")));
        Assert.assertEquals(WorkerInfo.State.WORKING, workerInfo.getState());
        Assert.assertNotNull(workerInfo.getStatus());
        Assert.assertFalse(workerInfo.getStatus().isPaused());
        Assert.assertNull(workerInfo.getStarted());
        Assert.assertEquals((Long)0L, workerInfo.getFailed());
        Assert.assertEquals((Long)0L, workerInfo.getProcessed());
    }
View Full Code Here

            /**
             * {@inheritDoc}
             */
            @Override
            public WorkerInfo doWork(final Jedis jedis) throws Exception {
                WorkerInfo workerInfo = null;
                if (jedis.sismember(key(WORKERS), workerName)) {
                    workerInfo = createWorker(workerName, jedis);
                }
                return workerInfo;
            }
View Full Code Here

        return JesqueUtils.createKey(this.config.getNamespace(), parts);
    }

    protected WorkerInfo createWorker(final String workerName, final Jedis jedis)
            throws ParseException, IOException {
        final WorkerInfo workerInfo = new WorkerInfo();
        workerInfo.setName(workerName);
        final String[] nameParts = COLON_PATTERN.split(workerName, 3);
        if (nameParts.length < 3) {
            throw new ParseException("Malformed worker name: " + workerName, 0);
        }
        workerInfo.setHost(nameParts[0]);
        workerInfo.setPid(nameParts[1]);
        workerInfo.setQueues(new ArrayList<String>(Arrays.asList(COMMA_PATTERN.split(nameParts[2]))));
        final String statusPayload = jedis.get(key(WORKER, workerName));
        if (statusPayload != null) {
            workerInfo.setStatus(ObjectMapperFactory.get().readValue(statusPayload, WorkerStatus.class));
            final WorkerInfo.State state = (workerInfo.getStatus().isPaused())
                    ? WorkerInfo.State.PAUSED
                    : WorkerInfo.State.WORKING;
            workerInfo.setState(state);
        } else {
            workerInfo.setState(WorkerInfo.State.IDLE);
        }
        final String startedStr = jedis.get(key(WORKER, workerName, STARTED));
        if (startedStr != null) {
            workerInfo.setStarted(new CompositeDateFormat().parse(startedStr));
        }
        final String failedStr = jedis.get(key(STAT, FAILED, workerName));
        if (failedStr != null) {
            workerInfo.setFailed(Long.parseLong(failedStr));
        } else {
            workerInfo.setFailed(0L);
        }
        final String processedStr = jedis.get(key(STAT, PROCESSED, workerName));
        if (processedStr != null) {
            workerInfo.setProcessed(Long.parseLong(processedStr));
        } else {
            workerInfo.setProcessed(0L);
        }
        return workerInfo;
    }
View Full Code Here

TOP

Related Classes of net.greghaines.jesque.meta.WorkerInfo

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.