def canceled(self): """ A property to indicate if a task has been canceled. :returns True is this task has been canceled, False otherwise. """ return is_revoked(self)
def test_is_revoked(self, inspect): task = mock.MagicMock() task.request.parent_id = None task.request.id = '123' task.request.hostname = 'hard@worker' worker_inspector = mock.MagicMock() inspect.return_value = worker_inspector worker_inspector.revoked.return_value = { task.request.hostname: [task.request.id] } # Revoked self.assertTrue(is_revoked(task)) # Not revoked task.request.id = '456' self.assertFalse(is_revoked(task))
def gw_task_success(sender=None, **rest): if is_builtin_celery_task(sender.name): return try: if not is_revoked(sender): _update_status(sender, JobStatus.SUCCESS) # For tasks revoked directly else: _update_status(sender, JobStatus.CANCELED) except AttributeError: pass except StateTransitionException: # Fetch the current status of the job status = sender.job_manager.refreshStatus() # If we are in CANCELING move to CANCELED if status == JobStatus.CANCELING or is_revoked(sender): _update_status(sender, JobStatus.CANCELED) else: raise