'Create job script and submit it to the DRM'

def queue_job(self, job_wrapper):

    include_metadata = asbool(job_wrapper.job_destination.params.get('embed_metadata_in_job', DEFAULT_EMBED_METADATA_IN_JOB))
    if (not self.prepare_job(job_wrapper, include_metadata=include_metadata)):
        return
    job_destination = job_wrapper.job_destination
    (shell_params, job_params) = self.parse_destination_params(job_destination.params)
    (shell, job_interface) = self.get_cli_plugins(shell_params, job_params)
    galaxy_id_tag = job_wrapper.get_id_tag()
    ajs = AsynchronousJobState(files_dir=job_wrapper.working_directory, job_wrapper=job_wrapper)
    job_file_kwargs = job_interface.job_script_kwargs(ajs.output_file, ajs.error_file, ajs.job_name)
    script = self.get_job_file(job_wrapper, exit_code_path=ajs.exit_code_file, **job_file_kwargs)
    try:
        self.write_executable_script(ajs.job_file, script)
    except:
        log.exception(('(%s)    failure    writing    job    script' % galaxy_id_tag))
        job_wrapper.fail('failure    preparing    job    script', exception=True)
        return
    if (job_wrapper.get_state() == model.Job.states.DELETED):
        log.info(('(%s)    Job    deleted    by    user    before    it    entered    the    queue' % galaxy_id_tag))
        if (job_wrapper.cleanup_job in ('always', 'onsuccess')):
            job_wrapper.cleanup()
        return
    log.debug(('(%s)    submitting    file:    %s' % (galaxy_id_tag, ajs.job_file)))
    cmd_out = shell.execute(job_interface.submit(ajs.job_file))
    if (cmd_out.returncode != 0):
        log.error(('(%s)    submission    failed    (stdout):    %s' % (galaxy_id_tag, cmd_out.stdout)))
        log.error(('(%s)    submission    failed    (stderr):    %s' % (galaxy_id_tag, cmd_out.stderr)))
        job_wrapper.fail('failure    submitting    job')
        return
    external_job_id = cmd_out.stdout.strip().split()[(-1)]
    if (not external_job_id):
        log.error(('(%s)    submission    did    not    return    a    job    identifier,    failing    job' % galaxy_id_tag))
        job_wrapper.fail('failure    submitting    job')
        return
    log.info(('(%s)    queued    with    identifier:    %s' % (galaxy_id_tag, external_job_id)))
    job_wrapper.set_job_destination(job_destination, external_job_id)
    ajs.job_id = external_job_id
    ajs.old_state = 'new'
    ajs.job_destination = job_destination
    self.monitor_queue.put(ajs)
