Set import job status when job starts and finishes

This commit is contained in:
Mouse Reeve 2022-11-05 13:45:17 -07:00
parent 59fe9e4d3b
commit 97513a43d6
3 changed files with 18 additions and 5 deletions

View file

@ -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")

View file

@ -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,
),
),
]

View file

@ -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"""