'Get the job current status from GoDocker
using job_id and update the status in galaxy.
If the job execution is successful, call
mark_as_finished() and return \'None\' to galaxy.
else if the job failed, call mark_as_failed()
and return \'None\' to galaxy.
else if the job is running or in pending state, simply
return the \'AsynchronousJobState object\' (job_state).'

def check_watched_item(self, job_state):

    '    This    function    is    called    by    check_watched_items()    where\n                                                                                param    job_state    is    an    object    of    AsynchronousJobState.\n                                                Expected    return    type    of    this    function    is    None    or\n                                                                                AsynchronousJobState    object    with    updated    running    status.\n                                '
    '    Get    task    from    GoDocker    '
    job_status_god = self.get_task(job_state.job_id)
    log.debug(((('Job    ID:    ' + str(job_state.job_id)) + '    Job    Status:    ') + str(job_status_god['status']['primary'])))
    if (job_status_god['status']['primary'] == 'over'):
        job_state.running = False
        job_state.job_wrapper.change_state(model.Job.states.OK)
        if self.create_log_file(job_state, job_status_god):
            self.mark_as_finished(job_state)
        else:
            self.mark_as_failed(job_state)
        'The    function    mark_as_finished()    executes:\n                                                                                                self.work_queue.put((self.finish_job,    job_state))\n                                            *self.finish_job    ->\n                                                job_state.job_wrapper.finish(    stdout,    stderr,    exit_code    )\n                                                job_state.job_wrapper.reclaim_ownership()\n                                                job_state.cleanup()\n                                            *self.work_queue.put(    method    ,    arg    )    ->\n                                                The    run_next()    method    starts    execution    on    starting    worker    threads.\n                                                This    run_next()    method    executes    method(arg)\n                                                                                                by    using    self.work_queue.get()\n                                            *Possible    outcomes    of    finish_job(job_state)    ->\n                                                job_state.job_wrapper.finish(    stdout,    stderr,    exit_code    )\n                                                job_state.job_wrapper.fail(    "Unable    to    finish    job",    exception=True)\n                                            *Similar    workflow    is    done    for    mark_as_failed()    method.\n                                                '
        return None
    elif (job_status_god['status']['primary'] == 'running'):
        job_state.running = True
        job_state.job_wrapper.change_state(model.Job.states.RUNNING)
        return job_state
    elif (job_status_god['status']['primary'] == 'pending'):
        return job_state
    elif (job_status_god['status']['exitcode'] not in [None, 0]):
        job_state.running = False
        job_state.job_wrapper.change_state(model.Job.states.ERROR)
        self.create_log_file(job_state, job_status_god)
        self.mark_as_failed(job_state)
        return None
    else:
        job_state.running = False
        self.create_log_file(job_state, job_status_god)
        self.mark_as_failed(job_state)
        return None
