def increment_completed_steps(self, steps=1):
"""
Increase the value of :py:attr:`completed_steps` by the given number and save, then check for cancellation.
If cancellation of the task has been requested, a TaskCanceledException
will be raised to abort execution. If any special cleanup is required,
this exception should be caught and handled appropriately.
This method should be called often enough to provide a useful
indication of progress, but not so often as to cause undue burden on
the database.
"""
UserTaskStatus.objects.filter(pk=self.id).update(completed_steps=F('completed_steps') + steps,
modified=now())
self.refresh_from_db(fields={'completed_steps', 'modified', 'state'})
if self.parent:
self.parent.increment_completed_steps(steps) # pylint: disable=no-member
# Was a cancellation command recently sent?
if self.state == self.CANCELED and not self.is_container:
raise TaskCanceledException
评论列表
文章目录