From 97513a43d63e2b6d2defbcc3d7940189fca06c73 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sat, 5 Nov 2022 13:45:17 -0700 Subject: [PATCH] Set import job status when job starts and finishes --- bookwyrm/importers/importer.py | 2 ++ .../migrations/0161_alter_importjob_status.py | 18 ++++++++++++++---- bookwyrm/models/import_job.py | 3 ++- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/bookwyrm/importers/importer.py b/bookwyrm/importers/importer.py index a3c522968..eb86e8ac2 100644 --- a/bookwyrm/importers/importer.py +++ b/bookwyrm/importers/importer.py @@ -135,6 +135,8 @@ def start_import_task(job_id): task = import_item_task.delay(item) item.task_id = task.id item.save() + job.status = "active" + job.save() @app.task(queue="low_priority") diff --git a/bookwyrm/migrations/0161_alter_importjob_status.py b/bookwyrm/migrations/0161_alter_importjob_status.py index d64b3e27e..44a1aea4c 100644 --- a/bookwyrm/migrations/0161_alter_importjob_status.py +++ b/bookwyrm/migrations/0161_alter_importjob_status.py @@ -6,13 +6,23 @@ from django.db import migrations, models class Migration(migrations.Migration): dependencies = [ - ('bookwyrm', '0160_auto_20221105_2030'), + ("bookwyrm", "0160_auto_20221105_2030"), ] operations = [ migrations.AlterField( - model_name='importjob', - name='status', - field=models.CharField(choices=[('pending', 'Pending'), ('active', 'Active'), ('complete', 'Complete'), ('stopped', 'Stopped')], default='pending', max_length=50, null=True), + model_name="importjob", + name="status", + field=models.CharField( + choices=[ + ("pending", "Pending"), + ("active", "Active"), + ("complete", "Complete"), + ("stopped", "Stopped"), + ], + default="pending", + max_length=50, + null=True, + ), ), ] diff --git a/bookwyrm/models/import_job.py b/bookwyrm/models/import_job.py index 6db2fd854..303e36657 100644 --- a/bookwyrm/models/import_job.py +++ b/bookwyrm/models/import_job.py @@ -116,8 +116,9 @@ class ImportItem(models.Model): job.updated_date = timezone.now() job.save() if not job.pending_items.exists() and not job.complete: + job.status = "complete" job.complete = True - job.save(update_fields=["complete"]) + job.save(update_fields=["complete", "status"]) def resolve(self): """try various ways to lookup a book"""