示例#1
0
 def test_perform(self):
     self.resq.enqueue(Basic,"test1")
     job = Job.reserve('basic',self.resq)
     self.resq.enqueue(TestProcess)
     job2 = Job.reserve('high', self.resq)
     assert job.perform() == "name:test1"
     assert job2.perform()
示例#2
0
 def test_requeue(self):
     self.resq.enqueue(Basic,"test1")
     job = Job.reserve('basic',self.resq)
     e = Exception('problem')
     fail_object = job.fail(e)
     assert self.resq.size('basic') == 0
     failure.requeue(self.resq, fail_object)
     assert self.resq.size('basic') == 1
     job = Job.reserve('basic',self.resq)
     assert job._queue == 'basic'
     assert job._payload == {'class':'tests.Basic','args':['test1']}
示例#3
0
 def test_requeue(self):
     self.resq.enqueue(self.job_class, "test1")
     job = Job.reserve(self.queue_name, self.resq)
     e = Exception("problem")
     fail_object = job.fail(e)
     assert self.resq.size(self.queue_name) == 0
     failure.requeue(self.resq, fail_object)
     assert self.resq.size(self.queue_name) == 1
     job = Job.reserve(self.queue_name, self.resq)
     assert job._queue == self.queue_name
     mod_with_class = "{module}.{klass}".format(module=self.job_class.__module__, klass=self.job_class.__name__)
     assert job._payload == {"class": mod_with_class, "args": ["test1"]}
示例#4
0
 def test_requeue(self):
     self.resq.enqueue(self.job_class,"test1")
     job = Job.reserve(self.queue_name,self.resq)
     e = Exception('problem')
     fail_object = job.fail(e)
     assert self.resq.size(self.queue_name) == 0
     failure.requeue(self.resq, fail_object)
     assert self.resq.size(self.queue_name) == 1
     job = Job.reserve(self.queue_name,self.resq)
     assert job._queue == self.queue_name
     mod_with_class = '{module}.{klass}'.format(
         module=self.job_class.__module__,
         klass=self.job_class.__name__)
     self.assertEqual(job._payload, {'class':mod_with_class,'args':['test1'],'enqueue_timestamp': job.enqueue_timestamp})
示例#5
0
 def test_working_on(self):
     name = "%s:%s:%s" % (os.uname()[1],os.getpid(),'basic')
     self.resq.enqueue(Basic,"test1")
     job = Job.reserve('basic', self.resq)
     worker = Worker(['basic'])
     worker.working_on(job)
     assert self.redis.exists("resque:worker:%s" % name)
示例#6
0
 def reserve(self):
     for q in self.queues:
         logger.info("Checking %s" % q)
         job = Job.reserve(q, self.resq, self.__str__())
         if job:
             print "Found job on %s" % q
             return job
示例#7
0
文件: worker.py 项目: mjrusso/pyres
 def reserve(self):
     for q in self.queues:
         logging.debug('checking queue %s' % q)
         job = Job.reserve(q, self.resq, self.__str__())
         if job:
             logging.info('Found job on %s' % q)
             return job
示例#8
0
文件: worker.py 项目: deepu/pyres
 def reserve(self):
     for q in self.queues:
         print "Checking %s" % q
         job = Job.reserve(q, self.resq)
         if job:
             print "Found job on %s" % q
             return job
示例#9
0
 def test_clear(self):
     self.resq.enqueue(self.job_class,"test1")
     job = Job.reserve(self.queue_name,self.resq)
     e = Exception('problem')
     job.fail(e)
     assert self.redis.llen('resque:failed') == 1
     failure.clear(self.resq)
     assert self.redis.llen('resque:failed') == 0
示例#10
0
 def test_clear(self):
     self.resq.enqueue(Basic,"test1")
     job = Job.reserve('basic',self.resq)
     e = Exception('problem')
     job.fail(e)
     assert self.redis.llen('resque:failed') == 1
     failure.clear(self.resq)
     assert self.redis.llen('resque:failed') == 0
示例#11
0
文件: worker.py 项目: fakechris/pyres
 def reserve(self):
     for q in self.queues:
         #print "Checking %s" % q
         job = Job.reserve(q, self.resq, self.__str__())
         if job:
             if self.verbose:
                 print "Found job on %s" % q
             return job
示例#12
0
 def test_create(self):
     self.resq.enqueue(self.job_class, "test1")
     job = Job.reserve(self.queue_name, self.resq)
     e = Exception("test")
     fail = failure.create(e, self.queue_name, job._payload)
     assert isinstance(fail._payload, dict)
     fail.save(self.resq)
     assert failure.count(self.resq) == 1
     assert self.redis.llen("resque:failed") == 1
示例#13
0
 def test_create(self):
     self.resq.enqueue(Basic,"test1")
     job = Job.reserve('basic',self.resq)
     e = Exception('test')
     fail = failure.create(e, 'basic', job._payload)
     assert isinstance(fail._payload, dict)
     fail.save()
     assert failure.count(self.resq) == 1
     assert self.redis.llen('resque:failed') == 1
示例#14
0
文件: test_resq.py 项目: aezell/pyres
 def test_enqueue_from_string(self):
     self.resq.enqueue_from_string("tests.Basic", "basic", "test1")
     name = "%s:%s:%s" % (os.uname()[1], os.getpid(), "basic")
     assert self.redis.llen("resque:queue:basic") == 1
     job = Job.reserve("basic", self.resq)
     worker = Worker(["basic"])
     worker.process(job)
     assert not self.redis.get("resque:worker:%s" % worker)
     assert not self.redis.get("resque:stat:failed")
     assert not self.redis.get("resque:stat:failed:%s" % name)
示例#15
0
 def test_state(self):
     worker = Worker(['basic'])
     assert worker.state() == 'idle'
     self.resq.enqueue_from_string('tests.Basic','basic','test1')
     worker.register_worker()
     job = Job.reserve('basic', self.resq)
     worker.working_on(job)
     assert worker.state() == 'working'
     worker.done_working()
     assert worker.state() == 'idle'
示例#16
0
 def test_enqueue_from_string(self):
     self.resq.enqueue_from_string('tests.Basic','basic','test1')
     name = "%s:%s:%s" % (os.uname()[1],os.getpid(),'basic')
     assert self.redis.llen("resque:queue:basic") == 1
     job = Job.reserve('basic', self.resq)
     worker = Worker(['basic'])
     worker.process(job)
     assert not self.redis.get('resque:worker:%s' % worker)
     assert not self.redis.get("resque:stat:failed")
     assert not self.redis.get("resque:stat:failed:%s" % name)
示例#17
0
 def test_working(self):
     worker = Worker(['basic'])
     self.resq.enqueue_from_string('tests.Basic','basic','test1')
     worker.register_worker()
     job = Job.reserve('basic', self.resq)
     worker.working_on(job)
     name = "%s:%s:%s" % (os.uname()[1],os.getpid(),'basic')
     workers = Worker.working(self.resq)
     assert len(workers) == 1
     assert str(worker) == str(workers[0])
     assert worker != workers[0]
示例#18
0
 def test_get_job(self):
     worker = Worker(['basic'])
     self.resq.enqueue(Basic,"test1")
     job = Job.reserve('basic', self.resq)
     worker.working_on(job)
     name = "%s:%s:%s" % (os.uname()[1],os.getpid(),'basic')
     assert worker.job() == ResQ.decode(self.redis.get('resque:worker:%s' % name))
     worker.done_working()
     w2 = Worker(['basic'])
     print w2.job()
     assert w2.job() == {}
示例#19
0
    def reserve(self, queues):
        """Fetch a job from one of the queues in ``queues`` and mark it
        as reserved. If no jobs are available, do nothing.

        :param queues: a list of queues to try to fetch from.
        :type queues: `list` of `str` or just `str`

        :returns: the reserved :class:`Job` or `None`
        :rtype: :class:`Job` or `None`
        """
        from pyres.job import Job
        return Job.reserve(queues, self)
示例#20
0
 def test_process(self):
     name = "%s:%s:%s" % (os.uname()[1],os.getpid(),'basic')
     self.resq.enqueue(Basic,"test1")
     job = Job.reserve('basic', self.resq)
     worker = Worker(['basic'])
     worker.process(job)
     assert not self.redis.get('resque:worker:%s' % worker)
     assert not self.redis.get("resque:stat:failed")
     assert not self.redis.get("resque:stat:failed:%s" % name)
     self.resq.enqueue(Basic,"test1")
     worker.process()
     assert not self.redis.get('resque:worker:%s' % worker)
     assert not self.redis.get("resque:stat:failed")
     assert not self.redis.get("resque:stat:failed:%s" % name)
示例#21
0
 def test_count(self):
     self.resq.enqueue(Basic,"test1")
     job = Job.reserve('basic',self.resq)
     job.fail("problem")
     assert failure.count(self.resq) == 1
     assert self.redis.llen('resque:failed') == 1
示例#22
0
 def test_all(self):
     self.resq.enqueue(self.job_class, "test1")
     job = Job.reserve(self.queue_name, self.resq)
     e = Exception('problem')
     job.fail(e)
     assert len(failure.all(self.resq, 0, 20)) == 1
示例#23
0
 def test_date_arg_type(self):
     dt = datetime.now().replace(microsecond=0)
     self.resq.enqueue(ReturnAllArgsJob, dt)
     job = Job.reserve('basic', self.resq)
     result = job.perform()
     assert result[0] == dt
示例#24
0
 def test_all(self):
     self.resq.enqueue(Basic,"test1")
     job = Job.reserve('basic',self.resq)
     e = Exception('problem')
     job.fail(e)
     assert len(failure.all(self.resq, 0, 20)) == 1
示例#25
0
 def test_reserve(self):
     self.resq.enqueue(Basic, "test1")
     job = Job.reserve('basic', self.resq)
     assert job._queue == 'basic'
     assert job._payload
     assert job._payload == {'class': 'tests.Basic', 'args': ['test1']}
示例#26
0
 def test_all(self):
     self.resq.enqueue(self.job_class,"test1")
     job = Job.reserve(self.queue_name,self.resq)
     e = Exception('problem')
     job.fail(e)
     assert len(failure.all(self.resq, 0, 20)) == 1
示例#27
0
 def test_reserve(self):
     self.resq.enqueue(Basic,"test1")
     job = Job.reserve('basic', self.resq)
     assert job._queue == 'basic'
     assert job._payload
     self.assertEqual(job._payload, {'class':'tests.Basic','args':['test1'],'enqueue_timestamp':job.enqueue_timestamp})
示例#28
0
文件: test_jobs.py 项目: EG5h/pyres
 def test_date_arg_type(self):
     dt = datetime.now().replace(microsecond=0)
     self.resq.enqueue(ReturnAllArgsJob, dt)
     job = Job.reserve('basic',self.resq)
     result = job.perform()
     assert result[0] == dt
示例#29
0
文件: horde.py 项目: Affectiva/pyres
 def reserve(self):
     self.logger.debug('checking queues: %s' % self.queues)
     job = Job.reserve(self.queues, self.resq, self.__str__())
     if job:
         self.logger.info('Found job on %s' % job._queue)
         return job
示例#30
0
 def test_reserve(self):
     self.resq.enqueue(Basic,"test1")
     job = Job.reserve('basic', self.resq)
     assert job._queue == 'basic'
     assert job._payload
     assert job._payload == {'class':'tests.Basic','args':['test1']}
示例#31
0
 def test_fail(self):
     self.resq.enqueue(Basic, "test1")
     job = Job.reserve('basic', self.resq)
     assert self.redis.llen('resque:failed') == 0
     job.fail("problem")
     assert self.redis.llen('resque:failed') == 1
示例#32
0
文件: tests.py 项目: deepu/pyres
 def test_fail(self):
     self.resq.enqueue(Basic,"test1")
     job = Job.reserve('basic',self.resq)
     assert self.redis.llen('failed') == 0
     job.fail("problem")
     assert self.redis.llen('failed') == 1
示例#33
0
 def test_count(self):
     self.resq.enqueue(self.job_class, "test1")
     job = Job.reserve(self.queue_name, self.resq)
     job.fail("problem")
     assert failure.count(self.resq) == 1
     assert self.redis.llen('resque:failed') == 1
示例#34
0
 def reserve(self, queues):
     from pyres.job import Job
     return Job.reserve(queues, self)
示例#35
0
文件: horde.py 项目: acmarques/pyres
 def reserve(self):
     self.logger.debug('checking queues: %s' % self.queues)
     job = Job.reserve(self.queues, self.resq, self.__str__())
     if job:
         self.logger.info('Found job on %s' % job._queue)
         return job
示例#36
0
文件: __init__.py 项目: jimklo/pyres
 def reserve(self, queue):
     from pyres.job import Job
     return Job.reserve(queue, self)
示例#37
0
文件: tests.py 项目: deepu/pyres
 def test_reserve(self):
     self.resq.enqueue(Basic,"test1")
     job = Job.reserve('basic', self.resq)
     assert job._queue == 'basic'
     assert job._payload