'Handle a job upon its termination in the DRM. This method is meant to
be overridden by subclasses to improve post-mortem and reporting of
failures.
Returns True if job was not actually terminal, None otherwise.'

def _complete_terminal_job(self, ajs, drmaa_state, **kwargs):

    if (drmaa_state == drmaa.JobState.FAILED):
        if (ajs.job_wrapper.get_state() != model.Job.states.DELETED):
            ajs.stop_job = False
            ajs.fail_message = 'The    cluster    DRM    system    terminated    this    job'
            self.work_queue.put((self.fail_job, ajs))
    elif (drmaa_state == drmaa.JobState.DONE):
        external_metadata = (not asbool(ajs.job_wrapper.job_destination.params.get('embed_metadata_in_job', True)))
        if external_metadata:
            self._handle_metadata_externally(ajs.job_wrapper, resolve_requirements=True)
        if (ajs.job_wrapper.get_state() != model.Job.states.DELETED):
            self.work_queue.put((self.finish_job, ajs))
