def test_worker_task_trace_handle_failure(self): tid = uuid() w = WorkerTaskTrace(mytask.name, tid, [4], {}) type_, value_, tb_ = self.create_exception(ValueError("foo")) w._store_errors = False w.handle_failure(value_, type_, tb_, "") self.assertEqual(mytask.backend.get_status(tid), states.PENDING) w._store_errors = True w.handle_failure(value_, type_, tb_, "") self.assertEqual(mytask.backend.get_status(tid), states.FAILURE)
def test_worker_task_trace_handle_retry(self): from celery.exceptions import RetryTaskError tid = uuid() w = WorkerTaskTrace(mytask.name, tid, [4], {}) type_, value_, tb_ = self.create_exception(ValueError("foo")) type_, value_, tb_ = self.create_exception( RetryTaskError(str(value_), exc=value_)) w._store_errors = False w.handle_retry(value_, type_, tb_, "") self.assertEqual(mytask.backend.get_status(tid), states.PENDING) w._store_errors = True w.handle_retry(value_, type_, tb_, "") self.assertEqual(mytask.backend.get_status(tid), states.RETRY)
def test_worker_task_trace_handle_failure(self): uuid = gen_unique_id() w = WorkerTaskTrace(mytask.name, uuid, [4], {}) type_, value_, tb_ = self.create_exception(ValueError("foo")) w._store_errors = False w.handle_failure(value_, type_, tb_, "") self.assertEqual(mytask.backend.get_status(uuid), states.PENDING) w._store_errors = True w.handle_failure(value_, type_, tb_, "") self.assertEqual(mytask.backend.get_status(uuid), states.FAILURE)
def test_worker_task_trace_handle_retry(self): from celery.exceptions import RetryTaskError uuid = gen_unique_id() w = WorkerTaskTrace(mytask.name, uuid, [4], {}) type_, value_, tb_ = self.create_exception(ValueError("foo")) type_, value_, tb_ = self.create_exception(RetryTaskError(str(value_), exc=value_)) w._store_errors = False w.handle_retry(value_, type_, tb_, "") self.assertEqual(mytask.backend.get_status(uuid), states.PENDING) w._store_errors = True w.handle_retry(value_, type_, tb_, "") self.assertEqual(mytask.backend.get_status(uuid), states.RETRY)
def jail(task_id, task_name, args, kwargs): return WorkerTaskTrace(task_name, task_id, args, kwargs)()