def cancel_task(self, user=None, recursive=True):
"""Cancel the task."""
if user is not None and not user.is_superuser:
if self.owner.username != user.username:
raise Exception("You are not task owner or superuser.")
try:
self.__lock(self.worker_id, new_state=TASK_STATES["CANCELED"], initial_states=(TASK_STATES["FREE"], TASK_STATES["ASSIGNED"], TASK_STATES["OPEN"], TASK_STATES["CREATED"]))
except (MultipleObjectsReturned, ObjectDoesNotExist):
raise Exception("Cannot cancel task %d, state is %s" % (self.id, self.get_state_display()))
if recursive:
for task in self.subtasks():
task.cancel_task(recursive=True)
self.logs.gzip_logs()
评论列表
文章目录