本文整理汇总了Python中limpyd_jobs.models.Job.add_job方法的典型用法代码示例。如果您正苦于以下问题:Python Job.add_job方法的具体用法?Python Job.add_job怎么用?Python Job.add_job使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类limpyd_jobs.models.Job
的用法示例。
在下文中一共展示了Job.add_job方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_requeue_delayed_jobs_put_back_ready_delayed_jobs_to_the_waiting_list
# 需要导入模块: from limpyd_jobs.models import Job [as 别名]
# 或者: from limpyd_jobs.models.Job import add_job [as 别名]
def test_requeue_delayed_jobs_put_back_ready_delayed_jobs_to_the_waiting_list(self):
queue = Queue.get_queue(name='test')
job1 = Job.add_job(identifier='job:1', queue_name='test', delayed_for=10)
job2 = Job.add_job(identifier='job:2', queue_name='test', delayed_for=1)
self.assertEqual(Queue.count_waiting_jobs('test'), 0)
self.assertEqual(Queue.count_delayed_jobs('test'), 2)
self.assertEqual(job1.status.hget(), STATUSES.DELAYED)
self.assertEqual(job2.status.hget(), STATUSES.DELAYED)
# must not move any jobs, too soon
queue.requeue_delayed_jobs()
self.assertEqual(Queue.count_waiting_jobs('test'), 0)
self.assertEqual(Queue.count_delayed_jobs('test'), 2)
self.assertEqual(job1.status.hget(), STATUSES.DELAYED)
self.assertEqual(job2.status.hget(), STATUSES.DELAYED)
sleep(1)
# now we should have one job in the waiting list
queue.requeue_delayed_jobs()
self.assertEqual(Queue.count_waiting_jobs('test'), 1)
self.assertEqual(Queue.count_delayed_jobs('test'), 1)
self.assertEqual(job1.status.hget(), STATUSES.DELAYED)
self.assertEqual(job2.status.hget(), STATUSES.WAITING)
waiting_jobs = queue.waiting.lmembers()
self.assertEqual(waiting_jobs, [job2.ident])
delayed_jobs = queue.delayed.zrange(0, -1, withscores=True)
self.assertEqual(delayed_jobs[0][0], job1.ident)
示例2: test_job_error_method_should_be_called
# 需要导入模块: from limpyd_jobs.models import Job [as 别名]
# 或者: from limpyd_jobs.models.Job import add_job [as 别名]
def test_job_error_method_should_be_called(self):
class ExceptionWithCode(Exception):
def __init__(self, message, code):
super(ExceptionWithCode, self).__init__(message)
self.message = message
self.code = code
def callback(job, queue):
raise ExceptionWithCode('foobar', 42)
job1 = Job.add_job(identifier='job:1', queue_name='test')
queue = Queue.get_queue(name='test')
worker = Worker(name='test', max_loops=1) # no callback
worker.run()
self.assertEqual(job1.status.hget(), STATUSES.ERROR)
self.assertIn(job1.get_pk(), queue.errors.lmembers())
self.assertEqual(len(Error.collection()), 1)
error = Error.get(identifier='job:1')
self.assertEqual(error.message.hget(), 'You must implement your own action')
self.assertEqual(error.code.hget(), None)
job2 = Job.add_job(identifier='job:2', queue_name='test')
queue = Queue.get_queue(name='test')
worker = Worker(name='test', max_loops=1, callback=callback) # callback with exception
worker.run()
self.assertEqual(job2.status.hget(), STATUSES.ERROR)
self.assertIn(job2.get_pk(), queue.errors.lmembers())
self.assertEqual(len(Error.collection()), 2)
error = Error.get(identifier='job:2')
self.assertEqual(error.message.hget(), 'foobar')
self.assertEqual(error.code.hget(), '42')
示例3: test_prepending_an_existing_job_should_move_it_at_the_beginning
# 需要导入模块: from limpyd_jobs.models import Job [as 别名]
# 或者: from limpyd_jobs.models.Job import add_job [as 别名]
def test_prepending_an_existing_job_should_move_it_at_the_beginning(self):
queue = Queue.get_queue(name='test', priority=1)
job1 = Job.add_job(identifier='job:1', queue_name='test', priority=1)
job2 = Job.add_job(identifier='job:2', queue_name='test', priority=1)
self.assertEqual(queue.waiting.lmembers(), [job1.ident, job2.ident])
Job.add_job(identifier='job:2', queue_name='test', priority=1, prepend=True)
self.assertEqual(queue.waiting.lmembers(), [job2.ident, job1.ident])
示例4: test_first_delayed_should_return_the_first_delayed_job_to_be_ready
# 需要导入模块: from limpyd_jobs.models import Job [as 别名]
# 或者: from limpyd_jobs.models.Job import add_job [as 别名]
def test_first_delayed_should_return_the_first_delayed_job_to_be_ready(self):
Job.add_job(identifier='job:1', queue_name='test', delayed_for=5)
job2 = Job.add_job(identifier='job:2', queue_name='test', delayed_for=1)
queue = Queue.get_queue(name='test')
attended_timestamp = datetime_to_score(parse(job2.delayed_until.hget()))
job_ident, timestamp = queue.first_delayed
self.assertEqual(job_ident, job2.ident)
self.assertEqual(timestamp, attended_timestamp)
timestamp = queue.first_delayed_time
self.assertEqual(timestamp, attended_timestamp)
示例5: test_run_ended_method_should_be_called
# 需要导入模块: from limpyd_jobs.models import Job [as 别名]
# 或者: from limpyd_jobs.models.Job import add_job [as 别名]
def test_run_ended_method_should_be_called(self):
class TestWorker(Worker):
passed = False
def run_ended(self):
super(TestWorker, self).run_ended()
self.passed = True
Job.add_job('job:1', 'test')
worker = TestWorker('test', max_loops=1) # one loop to run only one job
worker.run()
self.assertEqual(worker.passed, True)
示例6: test_wait_for_job_should_respond_with_queue_and_job_when_a_queue_is_not_empty
# 需要导入模块: from limpyd_jobs.models import Job [as 别名]
# 或者: from limpyd_jobs.models.Job import add_job [as 别名]
def test_wait_for_job_should_respond_with_queue_and_job_when_a_queue_is_not_empty(self):
queue = Queue.get_queue('test')
worker = Worker('test')
worker.test_content = None
class Thread(threading.Thread):
def run(self):
worker.update_keys()
queue, job = worker.wait_for_job()
worker.test_content = queue, job
# start listening
thread = Thread()
thread.start()
time.sleep(0.1)
# no job, nothing received
self.assertIsNone(worker.test_content)
# add a job
job = Job.add_job(queue_name='test', identifier='job:1')
time.sleep(0.1)
# info should be received
self.assertEqual(worker.test_content[0].get_pk(), queue.get_pk())
self.assertTrue(isinstance(worker.test_content[0], Queue))
self.assertEqual(worker.test_content[1].get_pk(), job.get_pk())
self.assertTrue(isinstance(worker.test_content[1], Job))
# job must no be in the queue anymore
self.assertNotIn(job.get_pk(), queue.waiting.lmembers())
示例7: test_adding_a_job_with_delayed_until_not_in_the_future_should_add_the_job_in_the_waiting_list
# 需要导入模块: from limpyd_jobs.models import Job [as 别名]
# 或者: from limpyd_jobs.models.Job import add_job [as 别名]
def test_adding_a_job_with_delayed_until_not_in_the_future_should_add_the_job_in_the_waiting_list(self):
queue = Queue.get_queue(name='test')
job = Job.add_job(identifier='job:1', queue_name='test', delayed_until=datetime.utcnow() - timedelta(seconds=5))
self.assertEqual(job.status.hget(), STATUSES.WAITING)
self.assertEqual(queue.waiting.llen(), 1)
self.assertEqual(queue.delayed.zcard(), 0)
示例8: test_job_started_method_should_be_called
# 需要导入模块: from limpyd_jobs.models import Job [as 别名]
# 或者: from limpyd_jobs.models.Job import add_job [as 别名]
def test_job_started_method_should_be_called(self):
class TestWorker(Worker):
passed = False
def execute():
pass
def job_started(self, job, queue):
super(TestWorker, self).job_started(job, queue)
self.passed = True
Job.add_job(identifier='job:1', queue_name='test')
worker = TestWorker(name='test', max_loops=1)
worker.run()
self.assertTrue(worker.passed)
示例9: test_add_error_method_should_add_an_error_instance
# 需要导入模块: from limpyd_jobs.models import Job [as 别名]
# 或者: from limpyd_jobs.models.Job import add_job [as 别名]
def test_add_error_method_should_add_an_error_instance(self):
e = ErrorTests.ExceptionWithCode('the answer', 42)
job = Job.add_job(identifier='job:1', queue_name='test')
error1 = Error.add_error(queue_name='test', job=job, error=e)
self.assertEqual(list(Error.collection()), [error1.pk.get()])
Error.add_error(queue_name='test', job=job, error=e)
self.assertEqual(len(Error.collection()), 2)
示例10: test_adding_an_existing_job_with_lower_priority_should_do_nothing
# 需要导入模块: from limpyd_jobs.models import Job [as 别名]
# 或者: from limpyd_jobs.models.Job import add_job [as 别名]
def test_adding_an_existing_job_with_lower_priority_should_do_nothing(self):
job1 = Job.add_job(identifier='job:1', queue_name='test', priority=3)
job2 = Job.add_job(identifier='job:1', queue_name='test', priority=1)
# only one job
self.assertEqual(job1.ident, job2.ident)
# is in high priority queue
queue = Queue.get_queue(name='test', priority=3)
self.assertEqual(queue.waiting.llen(), 1)
# nothing in high priority queue
queue = Queue.get_queue(name='test', priority=1)
self.assertEqual(queue.waiting.llen(), 0)
# we should still have original priority and status
self.assert_job_status_and_priority(job1, STATUSES.WAITING, '3')
# idem for job2 (which is, in fact, job1)
self.assert_job_status_and_priority(job2, STATUSES.WAITING, '3')
示例11: test_send_stop_signal_should_stop_worker
# 需要导入模块: from limpyd_jobs.models import Job [as 别名]
# 或者: from limpyd_jobs.models.Job import add_job [as 别名]
def test_send_stop_signal_should_stop_worker(self):
class TestWorker(Worker):
def execute(self, job, queue):
"""
Simulate a signal by directly calling the signal handler
"""
self.catch_end_signal(signal.SIGINT, None)
Job.add_job('job:1', 'test')
Job.add_job('job:2', 'test')
queue = Queue.get_queue('test')
worker = TestWorker('test', max_loops=2)
worker.run()
self.assertEqual(worker.end_signal_caught, True)
self.assertEqual(queue.success.llen(), 1)
self.assertEqual(queue.waiting.llen(), 1)
示例12: test_adding_an_existing_job_with_higher_priority_should_change_its_queue
# 需要导入模块: from limpyd_jobs.models import Job [as 别名]
# 或者: from limpyd_jobs.models.Job import add_job [as 别名]
def test_adding_an_existing_job_with_higher_priority_should_change_its_queue(self):
job1 = Job.add_job(identifier='job:1', queue_name='test', priority=1)
queue1 = Queue.get_queue(name='test', priority=1)
job2 = Job.add_job(identifier='job:1', queue_name='test', priority=2)
queue2 = Queue.get_queue(name='test', priority=2)
# only one job
self.assertEqual(job1.ident, job2.ident)
# not anymore in queue with priority 1
self.assertEqual(queue1.waiting.llen(), 0)
# but now in queue with priority 2
self.assertEqual(queue2.waiting.llen(), 1)
# the new prioriy must be stored, and status should still be waiting
self.assert_job_status_and_priority(job1, STATUSES.WAITING, '2')
# idem for job2 (which is, in fact, job1)
self.assert_job_status_and_priority(job2, STATUSES.WAITING, '2')
示例13: test_adding_a_job_with_delayed_for_should_add_the_job_in_the_delayed_list
# 需要导入模块: from limpyd_jobs.models import Job [as 别名]
# 或者: from limpyd_jobs.models.Job import add_job [as 别名]
def test_adding_a_job_with_delayed_for_should_add_the_job_in_the_delayed_list(self):
queue = Queue.get_queue(name='test')
job = Job.add_job(identifier='job:1', queue_name='test', delayed_for=5)
self.assertEqual(job.status.hget(), STATUSES.DELAYED)
self.assertEqual(queue.waiting.llen(), 0)
self.assertEqual(queue.delayed.zcard(), 1)
job2 = Job.add_job(identifier='job:2', queue_name='test', delayed_for=5.5)
self.assertEqual(job2.status.hget(), STATUSES.DELAYED)
self.assertEqual(queue.waiting.llen(), 0)
self.assertEqual(queue.delayed.zcard(), 2)
job3 = Job.add_job(identifier='job:3', queue_name='test', delayed_for=timedelta(seconds=5))
self.assertEqual(job3.status.hget(), STATUSES.DELAYED)
self.assertEqual(queue.waiting.llen(), 0)
self.assertEqual(queue.delayed.zcard(), 3)
示例14: test_get_from_ident_should_return_a_job
# 需要导入模块: from limpyd_jobs.models import Job [as 别名]
# 或者: from limpyd_jobs.models.Job import add_job [as 别名]
def test_get_from_ident_should_return_a_job(self):
job = Job.add_job(identifier='job:1', queue_name='test')
test_job = Job.get_from_ident('limpyd_jobs.models.Job:%s' % job.pk.get())
self.assertEqual(job.ident, test_job.ident)
job = JobFooBar.add_job(identifier='foobar:1', queue_name='foobar')
test_job = Job.get_from_ident('tests.models.JobFooBar:%s' % job.pk.get())
self.assertEqual(job.ident, test_job.ident)
示例15: test_count_delayed_jobs_should_return_the_number_of_delayed_jobs
# 需要导入模块: from limpyd_jobs.models import Job [as 别名]
# 或者: from limpyd_jobs.models.Job import add_job [as 别名]
def test_count_delayed_jobs_should_return_the_number_of_delayed_jobs(self):
self.assertEqual(Queue.count_delayed_jobs('test'), 0)
Job.add_job(identifier='job:1', queue_name='test', delayed_for=5)
self.assertEqual(Queue.count_delayed_jobs('test'), 1)
Job.add_job(identifier='job:2', queue_name='test')
self.assertEqual(Queue.count_delayed_jobs('test'), 1)
Job.add_job(identifier='foo:1', queue_name='foo', delayed_for=5)
Job.add_job(identifier='bar:1', queue_name='bar', delayed_for=5)
self.assertEqual(Queue.count_delayed_jobs(['foo', 'bar']), 2)
self.assertEqual(Queue.count_delayed_jobs(['test', 'foo', 'bar']), 3)