'Handle writing outputs to the object store.
This should be called regardless of whether the job was failed or not so
that writing of partial results happens and so that the object store is
cleaned up if the dataset has been purged.'

def __update_output(self, job, dataset, clean_only=False):

    dataset = dataset.dataset
    if (dataset not in job.output_library_datasets):
        purged = dataset.purged
        if ((not purged) and (not clean_only)):
            self.app.object_store.update_from_file(dataset, create=True)
        else:
            target = dataset.file_name
            if os.path.exists(target):
                os.remove(target)
