Skip to content

Commit

Permalink
Pass canvas creation to background task.
Browse files Browse the repository at this point in the history
  • Loading branch information
jayvarner committed Nov 27, 2024
1 parent 2d01531 commit 0f9fa91
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
9 changes: 3 additions & 6 deletions readux_ingest_ecds/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down
24 changes: 24 additions & 0 deletions readux_ingest_ecds/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 0f9fa91

Please sign in to comment.