diff --git a/readux_ingest_ecds/models.py b/readux_ingest_ecds/models.py index fa9e336..57ca494 100644 --- a/readux_ingest_ecds/models.py +++ b/readux_ingest_ecds/models.py @@ -469,15 +469,12 @@ def ingest(self): with open(trigger_file, "a", encoding="utf-8") as t_file: t_file.write(f"{image_file}\n") - local_ingest.create_canvases() - LOGGER.info(f"Canvases created for {pid}") - manifest.save() - from .tasks import add_ocr_task_local + from .tasks import add_canvases_task if os.environ["DJANGO_ENV"] == "test": - add_ocr_task_local(str(local_ingest.id), manifest.pid) + add_canvases_task(str(local_ingest.id), manifest.pid) else: - add_ocr_task_local.delay(str(local_ingest.id), manifest.pid) + add_canvases_task.delay(str(local_ingest.id), manifest.pid) else: LOGGER.warning(f"Ingest for {manifest.pid} already exists.") diff --git a/readux_ingest_ecds/tasks.py b/readux_ingest_ecds/tasks.py index f56fd40..47ac285 100644 --- a/readux_ingest_ecds/tasks.py +++ b/readux_ingest_ecds/tasks.py @@ -104,6 +104,30 @@ def bulk_ingest_task_ecds(ingest_id): bulk_ingest.ingest() +@app.task( + name="add_canvases_task", + autoretry_for=(Exception,), + retry_backoff=5, +) +def add_canvases_task(ingest_id, manifest_pid, *args, **kwargs): + """Function to create canvases + + Args: + ingest_id (string): ID for Local Ingest Object + manifest_pid (string): PID of Manifest being ingested + """ + LOGGER.info(f"Adding Canvases for {manifest_pid}") + local_ingest = Local.objects.get(pk=ingest_id) + local_ingest.create_canvases() + LOGGER.info(f"Canvases created for {manifest_pid}") + local_ingest.manifest.save() + + if os.environ["DJANGO_ENV"] == "test": + add_ocr_task_local(str(local_ingest.id), manifest_pid) + else: + add_ocr_task_local.delay(str(local_ingest.id), manifest_pid) + + @app.task( name="add_ocr_task_local_ecds", base=FinalTask,