models.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:django-user-tasks 作者: edx 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号