'Recovers jobs stuck in the queued/running state when Galaxy started'

def recover(self, job, job_wrapper):

    job_id = job.get_job_runner_external_id()
    pbs_job_state = AsynchronousJobState()
    pbs_job_state.output_file = ('%s/%s.o' % (self.app.config.cluster_files_directory, job.id))
    pbs_job_state.error_file = ('%s/%s.e' % (self.app.config.cluster_files_directory, job.id))
    pbs_job_state.exit_code_file = ('%s/%s.ec' % (self.app.config.cluster_files_directory, job.id))
    pbs_job_state.job_file = ('%s/%s.sh' % (self.app.config.cluster_files_directory, job.id))
    pbs_job_state.job_id = str(job_id)
    pbs_job_state.runner_url = job_wrapper.get_job_runner_url()
    pbs_job_state.job_destination = job_wrapper.job_destination
    job_wrapper.command_line = job.command_line
    pbs_job_state.job_wrapper = job_wrapper
    if (job.state == model.Job.states.RUNNING):
        log.debug(('(%s/%s)    is    still    in    running    state,    adding    to    the    PBS    queue' % (job.id, job.get_job_runner_external_id())))
        pbs_job_state.old_state = 'R'
        pbs_job_state.running = True
        self.monitor_queue.put(pbs_job_state)
    elif (job.state == model.Job.states.QUEUED):
        log.debug(('(%s/%s)    is    still    in    PBS    queued    state,    adding    to    the    PBS    queue' % (job.id, job.get_job_runner_external_id())))
        pbs_job_state.old_state = 'Q'
        pbs_job_state.running = False
        self.monitor_queue.put(pbs_job_state)
