本文整理汇总了Python中celery.worker.job.TaskWrapper类的典型用法代码示例。如果您正苦于以下问题:Python TaskWrapper类的具体用法?Python TaskWrapper怎么用?Python TaskWrapper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TaskWrapper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_execute_success_no_kwargs
def test_execute_success_no_kwargs(self):
tid = gen_unique_id()
tw = TaskWrapper(mytask_no_kwargs.name, tid, [4], {})
self.assertEqual(tw.execute(), 256)
meta = TaskMeta.objects.get(task_id=tid)
self.assertEqual(meta.result, 256)
self.assertEqual(meta.status, states.SUCCESS)
示例2: test_executed_bit
def test_executed_bit(self):
from celery.worker.job import AlreadyExecutedError
tw = TaskWrapper(mytask.name, gen_unique_id(), [], {})
self.assertFalse(tw.executed)
tw._set_executed_bit()
self.assertTrue(tw.executed)
self.assertRaises(AlreadyExecutedError, tw._set_executed_bit)
示例3: test_execute_fail
def test_execute_fail(self):
tid = gen_unique_id()
tw = TaskWrapper(mytask_raising.name, tid, [4], {"f": "x"})
self.assertIsInstance(tw.execute(), ExceptionInfo)
meta = TaskMeta.objects.get(task_id=tid)
self.assertEqual(meta.status, states.FAILURE)
self.assertIsInstance(meta.result, KeyError)
示例4: test_execute
def test_execute(self):
tid = gen_unique_id()
tw = TaskWrapper("cu.mytask", tid, mytask, [4], {"f": "x"})
self.assertEquals(tw.execute(), 256)
meta = TaskMeta.objects.get(task_id=tid)
self.assertEquals(meta.result, 256)
self.assertEquals(meta.status, "DONE")
示例5: test_execute
def test_execute(self):
tid = gen_unique_id()
tw = TaskWrapper(mytask.name, tid, [4], {"f": "x"})
self.assertEquals(tw.execute(), 256)
meta = TaskMeta.objects.get(task_id=tid)
self.assertEquals(meta.result, 256)
self.assertEquals(meta.status, "SUCCESS")
示例6: test_send_email
def test_send_email(self):
from celery import conf
from celery.worker import job
old_mail_admins = job.mail_admins
old_enable_mails = conf.CELERY_SEND_TASK_ERROR_EMAILS
mail_sent = [False]
def mock_mail_admins(*args, **kwargs):
mail_sent[0] = True
job.mail_admins = mock_mail_admins
conf.CELERY_SEND_TASK_ERROR_EMAILS = True
try:
tw = TaskWrapper(mytask.name, gen_unique_id(), [1], {"f": "x"})
try:
raise KeyError("foo")
except KeyError:
einfo = ExceptionInfo(sys.exc_info())
tw.on_failure(einfo)
self.assertTrue(mail_sent[0])
mail_sent[0] = False
conf.CELERY_SEND_TASK_ERROR_EMAILS = False
tw.on_failure(einfo)
self.assertFalse(mail_sent[0])
finally:
job.mail_admins = old_mail_admins
conf.CELERY_SEND_TASK_ERROR_EMAILS = old_enable_mails
示例7: test_execute_using_pool
def test_execute_using_pool(self):
tid = gen_unique_id()
tw = TaskWrapper(mytask.name, tid, [4], {"f": "x"})
p = TaskPool(2)
p.start()
asyncres = tw.execute_using_pool(p)
self.assertEqual(asyncres.get(), 256)
p.stop()
示例8: test_execute_using_pool
def test_execute_using_pool(self):
tid = gen_unique_id()
tw = TaskWrapper("cu.mytask", tid, mytask, [4], {"f": "x"})
p = TaskPool(2)
p.start()
asyncres = tw.execute_using_pool(p)
self.assertTrue(asyncres.get(), 256)
p.stop()
示例9: test_execute_fail
def test_execute_fail(self):
tid = gen_unique_id()
tw = TaskWrapper("cu.mytask-raising", tid, mytask_raising, [4],
{"f": "x"})
self.assertTrue(isinstance(tw.execute(), ExceptionInfo))
meta = TaskMeta.objects.get(task_id=tid)
self.assertEquals(meta.status, "FAILURE")
self.assertTrue(isinstance(meta.result, KeyError))
示例10: test_execute_success_some_kwargs
def test_execute_success_some_kwargs(self):
tid = gen_unique_id()
tw = TaskWrapper(mytask_some_kwargs.name, tid, [4], {})
self.assertEqual(tw.execute(logfile="foobaz.log"), 256)
meta = TaskMeta.objects.get(task_id=tid)
self.assertEqual(some_kwargs_scratchpad.get("logfile"), "foobaz.log")
self.assertEqual(meta.result, 256)
self.assertEqual(meta.status, states.SUCCESS)
示例11: test_execute_ack
def test_execute_ack(self):
tid = gen_unique_id()
tw = TaskWrapper(mytask.name, tid, [4], {"f": "x"},
on_ack=on_ack)
self.assertEqual(tw.execute(), 256)
meta = TaskMeta.objects.get(task_id=tid)
self.assertTrue(scratch["ACK"])
self.assertEqual(meta.result, 256)
self.assertEqual(meta.status, states.SUCCESS)
示例12: test_execute_ack
def test_execute_ack(self):
tid = gen_unique_id()
tw = TaskWrapper("cu.mytask", tid, mytask, [4], {"f": "x"},
on_acknowledge=on_ack)
self.assertEquals(tw.execute(), 256)
meta = TaskMeta.objects.get(task_id=tid)
self.assertTrue(scratch["ACK"])
self.assertEquals(meta.result, 256)
self.assertEquals(meta.status, "DONE")
示例13: test_default_kwargs
def test_default_kwargs(self):
tid = gen_unique_id()
tw = TaskWrapper("cu.mytask", tid, mytask, [4], {"f": "x"})
self.assertEquals(tw.extend_with_default_kwargs(10, "some_logfile"), {
"f": "x",
"logfile": "some_logfile",
"loglevel": 10,
"task_id": tw.task_id,
"task_name": tw.task_name})
示例14: test_default_kwargs
def test_default_kwargs(self):
tid = gen_unique_id()
tw = TaskWrapper(mytask.name, tid, [4], {"f": "x"})
self.assertDictEqual(
tw.extend_with_default_kwargs(10, "some_logfile"), {
"f": "x",
"logfile": "some_logfile",
"loglevel": 10,
"task_id": tw.task_id,
"task_retries": 0,
"task_is_eager": False,
"delivery_info": {},
"task_name": tw.task_name})
示例15: test_safe_process_task_raise_regular
def test_safe_process_task_raise_regular(self):
worker = self.worker
worker.pool = MockPool(raise_regular=True)
backend = MockBackend()
m = create_message(backend, task="c.u.foo", args=[4, 8, 10], kwargs={})
task = TaskWrapper.from_message(m, m.decode())
worker.safe_process_task(task)
worker.pool.stop()