code: def finish(queue_name, task_id, owner, error=False):
      
      task = _get_task_with_policy(queue_name, task_id, owner)
  
      if not task.status == WorkQueue.LIVE:
          logging.warning('Finishing already dead task. queue=%r, task_id=%r, '
                          'owner=%r, status=%r',
                          task.queue_name, task_id, owner, task.status)
          return False
  
      if not error:
          task.status = WorkQueue.DONE
      else:
          task.status = WorkQueue.ERROR
  
      task.finished = datetime.datetime.utcnow()
      db.session.add(task)
  
      signals.task_updated.send(app, task=task)
  
      return True
docs: Marks a work item on a queue as finished.
  
      Args:
          queue_name: Name of the queue the work item is on.
          task_id: ID of the task that is finished.
          owner: Who or what has the current lease on the task.
          error: Defaults to false. True if this task's final state is an error.
  
      Returns:
          True if the task has been finished for the first time; False if the
          task was already finished.
  
      Raises:
          TaskDoesNotExistError if the task does not exist.
          LeaseExpiredError if the lease is no longer active.
          NotOwnerError if the specified owner no longer owns the task.