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