def run_task(self, result_id, runjob_id, *args, **kwargs): runjob = RunJob.objects.get(pk=runjob_id) if runjob.needs_input: if runjob.status == RunJobStatus.RUN_ONCE_WAITING: self.retry(args=[result_id, runjob_id], *args, countdown=10, **kwargs) else: # This is the first time the job is running. taskutil.set_running(runjob) page_path = runjob.page.compat_file_path self._create_temp_neon_directory(runjob) mei_path = taskutil.get_input_path(runjob, result_id) shutil.copy(mei_path, live_mei_path(runjob)) shutil.copy(live_mei_path(runjob), backup_mei_path(runjob)) page_image = Image.open(page_path) page_image.save(compressed_image_path(runjob), quality=40) taskutil.set_run_once_waiting(runjob) self.retry(args=[result_id, runjob_id], *args, countdown=10, **kwargs) else: taskutil.set_running(runjob) result = taskutil.init_result(runjob) taskutil.save_result(result, live_mei_path(runjob)) return str(result.uuid)
def save_result(self, runjob, mei_document): result = taskutil.init_result(runjob) temp_mei_path = taskutil.create_temp_path(ext='mei') pymei.write(mei_document, temp_mei_path) taskutil.save_result(result, temp_mei_path) result.result_type = settings.MEI taskutil.save_instance(result) return result