'Cancel the given job. The job\'s state will be set to ERROR.
Any running tasks will be cancelled, and any queued/pending
tasks will be marked as DELETED so that runners know not
to run those tasks.'

def _cancel_job(self, job_wrapper, task_wrappers):

    job = job_wrapper.get_job()
    job.set_state(model.Job.states.ERROR)
    for task_wrapper in task_wrappers:
        task = task_wrapper.get_task()
        task_state = task.get_state()
        if (model.Task.states.QUEUED == task_state):
            log.debug(('_cancel_job    for    job    %d:    Task    %d    is    not    running;    setting    state    to    DELETED' % (job.get_id(), task.get_id())))
            task_wrapper.change_state(task.states.DELETED)
    sleep(5)
    for task_wrapper in task_wrappers:
        if (model.Task.states.RUNNING == task_wrapper.get_state()):
            task = task_wrapper.get_task()
            log.debug(('_cancel_job    for    job    %d:    Stopping    running    task    %d' % (job.get_id(), task.get_id())))
            job_wrapper.app.job_manager.job_handler.dispatcher.stop(task)
