本文整理汇总了Python中openerp.addons.connector.queue.job.Job类的典型用法代码示例。如果您正苦于以下问题:Python Job类的具体用法?Python Job怎么用?Python Job使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Job类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_infinite_retryable_error
def test_infinite_retryable_error(self):
test_job = Job(func=retryable_error_task,
max_retries=0)
self.assertEqual(test_job.retry, 0)
with self.assertRaises(RetryableJobError):
test_job.perform(self.session)
self.assertEqual(test_job.retry, 1)
示例2: _run_job
def _run_job(self, job_id):
job_obj = self.registry('queue.job')
job = job_obj.browse(self.cr, self.uid, job_id)
(func_name, args, kwargs) = _unpickle(job.func)
runnable_job = Job(func=func_name, args=args, kwargs=kwargs, priority=job.priority, eta=None, job_uuid=job.uuid, description=job.name)
runnable_job.user_id = self.session.uid
return runnable_job.perform(self.session)
示例3: test_perform_args
def test_perform_args(self):
test_job = Job(func=dummy_task_args,
model_name='res.users',
args=('o', 'k'),
kwargs={'c': '!'})
result = test_job.perform(self.session)
self.assertEqual(result, 'ok!')
示例4: test_set_pending
def test_set_pending(self):
job_a = Job(func=task_a)
job_a.set_pending(result='test')
self.assertEquals(job_a.state, PENDING)
self.assertFalse(job_a.date_enqueued)
self.assertFalse(job_a.date_started)
self.assertEquals(job_a.retry, 0)
self.assertEquals(job_a.result, 'test')
示例5: test_job_worker
def test_job_worker(self):
worker = self.env["queue.worker"].create({"uuid": "57569b99-c2c1-47b6-aad1-72f953c92c87"})
test_job = Job(func=dummy_task_args, model_name="res.users", args=("o", "k"), kwargs={"c": "!"})
test_job.worker_uuid = worker.uuid
storage = OpenERPJobStorage(self.session)
self.assertEqual(storage._worker_id(worker.uuid), worker.id)
storage.store(test_job)
job_read = storage.load(test_job.uuid)
self.assertEqual(job_read.worker_uuid, worker.uuid)
示例6: test_set_started
def test_set_started(self):
job_a = Job(func=task_a)
datetime_path = "openerp.addons.connector.queue.job.datetime"
with mock.patch(datetime_path, autospec=True) as mock_datetime:
mock_datetime.now.return_value = datetime(2015, 3, 15, 16, 41, 0)
job_a.set_started()
self.assertEquals(job_a.state, STARTED)
self.assertEquals(job_a.date_started, datetime(2015, 3, 15, 16, 41, 0))
示例7: test_postpone
def test_postpone(self):
job_a = Job(func=task_a)
datetime_path = 'openerp.addons.connector.queue.job.datetime'
with mock.patch(datetime_path, autospec=True) as mock_datetime:
mock_datetime.now.return_value = datetime(2015, 3, 15, 16, 41, 0)
job_a.postpone(result='test', seconds=60)
self.assertEquals(job_a.eta, datetime(2015, 3, 15, 16, 42, 0))
self.assertEquals(job_a.result, 'test')
self.assertFalse(job_a.exc_info)
示例8: test_read
def test_read(self):
eta = datetime.now() + timedelta(hours=5)
test_job = Job(func=dummy_task_args,
model_name='res.users',
args=('o', 'k'),
kwargs={'c': '!'},
priority=15,
eta=eta,
description="My description")
test_job.user_id = 1
test_job.company_id = self.env.ref("base.main_company").id
storage = OpenERPJobStorage(self.session)
storage.store(test_job)
job_read = storage.load(test_job.uuid)
self.assertEqual(test_job.uuid, job_read.uuid)
self.assertEqual(test_job.model_name, job_read.model_name)
self.assertEqual(test_job.func, job_read.func)
self.assertEqual(test_job.args, job_read.args)
self.assertEqual(test_job.kwargs, job_read.kwargs)
self.assertEqual(test_job.func_name, job_read.func_name)
self.assertEqual(test_job.func_string, job_read.func_string)
self.assertEqual(test_job.description, job_read.description)
self.assertEqual(test_job.state, job_read.state)
self.assertEqual(test_job.priority, job_read.priority)
self.assertEqual(test_job.exc_info, job_read.exc_info)
self.assertEqual(test_job.result, job_read.result)
self.assertEqual(test_job.user_id, job_read.user_id)
self.assertEqual(test_job.company_id, job_read.company_id)
delta = timedelta(seconds=1) # DB does not keep milliseconds
self.assertAlmostEqual(test_job.date_created, job_read.date_created,
delta=delta)
self.assertAlmostEqual(test_job.date_started, job_read.date_started,
delta=delta)
self.assertAlmostEqual(test_job.date_enqueued, job_read.date_enqueued,
delta=delta)
self.assertAlmostEqual(test_job.date_done, job_read.date_done,
delta=delta)
self.assertAlmostEqual(test_job.eta, job_read.eta,
delta=delta)
test_date = datetime(2015, 3, 15, 21, 7, 0)
job_read.date_enqueued = test_date
job_read.date_started = test_date
job_read.date_done = test_date
job_read.canceled = True
storage.store(job_read)
job_read = storage.load(test_job.uuid)
self.assertAlmostEqual(job_read.date_started, test_date,
delta=delta)
self.assertAlmostEqual(job_read.date_enqueued, test_date,
delta=delta)
self.assertAlmostEqual(job_read.date_done, test_date,
delta=delta)
self.assertEqual(job_read.canceled, True)
示例9: test_set_done
def test_set_done(self):
job_a = Job(func=task_a)
datetime_path = "openerp.addons.connector.queue.job.datetime"
with mock.patch(datetime_path, autospec=True) as mock_datetime:
mock_datetime.now.return_value = datetime(2015, 3, 15, 16, 41, 0)
job_a.set_done(result="test")
self.assertEquals(job_a.state, DONE)
self.assertEquals(job_a.result, "test")
self.assertEquals(job_a.date_done, datetime(2015, 3, 15, 16, 41, 0))
self.assertFalse(job_a.worker_uuid)
self.assertFalse(job_a.exc_info)
示例10: test_set_enqueued
def test_set_enqueued(self):
job_a = Job(func=task_a)
worker = mock.Mock(name="Worker")
uuid = "ae7d1161-dc34-40b1-af06-8057c049133e"
worker.uuid = "ae7d1161-dc34-40b1-af06-8057c049133e"
datetime_path = "openerp.addons.connector.queue.job.datetime"
with mock.patch(datetime_path, autospec=True) as mock_datetime:
mock_datetime.now.return_value = datetime(2015, 3, 15, 16, 41, 0)
job_a.set_enqueued(worker)
self.assertEquals(job_a.state, ENQUEUED)
self.assertEquals(job_a.date_enqueued, datetime(2015, 3, 15, 16, 41, 0))
self.assertEquals(job_a.worker_uuid, uuid)
self.assertFalse(job_a.date_started)
示例11: test_job_worker
def test_job_worker(self):
worker = self.env['queue.worker'].create(
{'uuid': '57569b99-c2c1-47b6-aad1-72f953c92c87'}
)
test_job = Job(func=dummy_task_args,
model_name='res.users',
args=('o', 'k'),
kwargs={'c': '!'})
test_job.worker_uuid = worker.uuid
storage = OpenERPJobStorage(self.session)
self.assertEqual(storage._worker_id(worker.uuid), worker.id)
storage.store(test_job)
job_read = storage.load(test_job.uuid)
self.assertEqual(job_read.worker_uuid, worker.uuid)
示例12: test_retry_pattern_no_zero
def test_retry_pattern_no_zero(self):
""" When we specify a retry pattern without 0, uses RETRY_INTERVAL"""
test_pattern = {3: 180}
job(retryable_error_task, retry_pattern=test_pattern)
test_job = Job(func=retryable_error_task, max_retries=0)
test_job.retry += 1
self.assertEqual(test_job.retry, 1)
self.assertEqual(test_job._get_retry_seconds(), RETRY_INTERVAL)
test_job.retry += 1
self.assertEqual(test_job.retry, 2)
self.assertEqual(test_job._get_retry_seconds(), RETRY_INTERVAL)
test_job.retry += 1
self.assertEqual(test_job.retry, 3)
self.assertEqual(test_job._get_retry_seconds(), 180)
test_job.retry += 1
self.assertEqual(test_job.retry, 4)
self.assertEqual(test_job._get_retry_seconds(), 180)
示例13: test_unicode
def test_unicode(self):
test_job = Job(func=dummy_task_args,
model_name='res.users',
args=(u'öô¿‽', u'ñě'),
kwargs={'c': u'ßø'},
priority=15,
description=u"My dé^Wdescription")
test_job.user_id = 1
storage = OpenERPJobStorage(self.session)
storage.store(test_job)
job_read = storage.load(test_job.uuid)
self.assertEqual(test_job.args, job_read.args)
self.assertEqual(job_read.args, ('res.users', u'öô¿‽', u'ñě'))
self.assertEqual(test_job.kwargs, job_read.kwargs)
self.assertEqual(job_read.kwargs, {'c': u'ßø'})
self.assertEqual(test_job.description, job_read.description)
self.assertEqual(job_read.description, u"My dé^Wdescription")
示例14: test_accented_bytestring
def test_accented_bytestring(self):
job = Job(func=dummy_task_args,
model_name='res.users',
args=('öô¿‽', 'ñě'),
kwargs={'c': 'ßø'},
priority=15,
description="My dé^Wdescription")
job.user_id = 1
storage = OpenERPJobStorage(self.session)
storage.store(job)
job_read = storage.load(job.uuid)
self.assertEqual(job.args, job_read.args)
self.assertEqual(job_read.args, ('res.users', 'öô¿‽', 'ñě'))
self.assertEqual(job.kwargs, job_read.kwargs)
self.assertEqual(job_read.kwargs, {'c': 'ßø'})
# the job's description has been created as bytestring but is
# decoded to utf8 by the ORM so make them comparable
self.assertEqual(job.description, job_read.description.encode('utf8'))
self.assertEqual(job_read.description, "My dé^Wdescription".decode('utf8'))
示例15: test_unicode
def test_unicode(self):
test_job = Job(
func=dummy_task_args,
model_name="res.users",
args=(u"öô¿‽", u"ñě"),
kwargs={"c": u"ßø"},
priority=15,
description=u"My dé^Wdescription",
)
test_job.user_id = 1
storage = OpenERPJobStorage(self.session)
storage.store(test_job)
job_read = storage.load(test_job.uuid)
self.assertEqual(test_job.args, job_read.args)
self.assertEqual(job_read.args, ("res.users", u"öô¿‽", u"ñě"))
self.assertEqual(test_job.kwargs, job_read.kwargs)
self.assertEqual(job_read.kwargs, {"c": u"ßø"})
self.assertEqual(test_job.description, job_read.description)
self.assertEqual(job_read.description, u"My dé^Wdescription")