本文整理汇总了Python中pq.job.Job类的典型用法代码示例。如果您正苦于以下问题:Python Job类的具体用法?Python Job怎么用?Python Job使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Job类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
def setUp(self):
job = Job.create(func=div_by_zero, args=(1, 2, 3))
job.origin = 'fake'
job.timeout = 200
job.save()
self.job = job
self.fq = get_failed_queue()
示例2: test_get_job_or_promise
def test_get_job_or_promise(self):
"""Test get a promise of a job in the future"""
job, promise, timeout = Job._get_job_or_promise(
self.q.connection, self.q, self.timeout)
self.assertLessEqual(timeout, self.timeout)
self.assertIsNone(job)
self.assertEqual(promise, self.q.name)
示例3: setUp
def setUp(self):
self.q = Queue()
self.q.save()
self.job = Job.create(
func=say_hello,
args=('Nick',),
kwargs=dict(foo='bar')
)
示例4: test_get_job_no_promise
def test_get_job_no_promise(self):
"""Test get job and no promise"""
job, promise, timeout = Job._get_job_or_promise(
self.q.connection, self.q, self.timeout)
self.assertEqual(timeout, self.timeout)
self.assertEquals(job.id, self.job.id)
self.assertIsNone(promise)
示例5: test_create_job_from_string_function
def test_create_job_from_string_function(self):
"""Creation of jobs using string specifier."""
job = Job.create(func='test_pq.fixtures.say_hello', args=('World',))
# Job data is set
self.assertEquals(job.func, say_hello)
self.assertIsNone(job.instance)
self.assertEquals(job.args, ('World',))
示例6: test_create_instance_method_job
def test_create_instance_method_job(self):
"""Creation of jobs for instance methods."""
c = Calculator(2)
job = Job.create(func=c.calculate, args=(3, 4))
# Job data is set
self.assertEquals(job.func, c.calculate)
self.assertEquals(job.instance, c)
self.assertEquals(job.args, (3, 4))
示例7: test_job_get_schedule_options
def test_job_get_schedule_options(self):
"""Test the job schedule property"""
j = Job.create(
do_nothing,
interval=600,
between='2-4',
repeat=10,
weekdays=(0,1,2)
)
self.assertIsNotNone(j.get_schedule_options())
示例8: test_get_no_job_no_promise
def test_get_no_job_no_promise(self):
"""Test get no job and no promise"""
# job is in the future beyond the current
# worker timeout
job, promise, timeout = Job._get_job_or_promise(
self.q.connection, self.q, 1)
self.assertEqual(timeout, 1)
self.assertIsNone(job)
self.assertIsNone(promise)
示例9: test_get_earlier_job_no_promise
def test_get_earlier_job_no_promise(self):
"""Test get earlier job and no promise"""
# Job enqueue after the first scheduled job
# but to be exec ahead of the scheduled job
now_job = self.q.enqueue(do_nothing)
job, promise, timeout = Job._get_job_or_promise(
self.q.connection, self.q, 60)
# timeout should remain the same
self.assertEqual(timeout, 60)
self.assertEqual(now_job.id, job.id)
self.assertIsNone(promise)
示例10: test_scheduled_job_create
def test_scheduled_job_create(self):
""" Test extra kwargs """
dt = datetime(2013,1,1, tzinfo=utc)
rd = relativedelta(months=1, days=-1)
job = Job.create(func=some_calculation,
args=(3, 4), kwargs=dict(z=2),
scheduled_for = dt,
repeat = -1,
interval = rd,
between = '0-24'
)
job.save()
job = Job.objects.get(pk=job.id)
self.assertEqual(rd, job.interval)
self.assertEqual(dt, job.scheduled_for)
示例11: test_job_create
def test_job_create(self):
job = Job.create(func=some_calculation, args=(3, 4), kwargs=dict(z=2))
self.assertIsNotNone(job.created_at)
self.assertIsNotNone(job.description)
self.assertIsNone(job.instance)
# Job data is set...
self.assertEquals(job.func, some_calculation)
self.assertEquals(job.args, (3, 4))
self.assertEquals(job.kwargs, {'z': 2})
# ...but metadata is not
self.assertIsNone(job.origin)
self.assertIsNone(job.enqueued_at)
示例12: test_work_is_unreadable
def test_work_is_unreadable(self):
"""Unreadable jobs are put on the failed queue."""
self.assertEqual(self.fq.count, 0)
self.assertEqual(self.q.count, 0)
# NOTE: We have to fake this enqueueing for this test case.
# What we're simulating here is a call to a function that is not
# importable from the worker process.
job = Job.create(func=div_by_zero, args=(3,))
job.save()
job.instance = 'nonexisting_job'
job.queue = self.q
job.save()
self.assertEqual(self.q.count, 1)
# All set, we're going to process it
self.w.work(burst=True) # should silently pass
self.assertEqual(self.q.count, 0)
self.assertEqual(self.fq.count, 1)
示例13: setUp
def setUp(self):
self.job = Job.create(func=some_calculation, args=(3, 4), kwargs=dict(z=2))