forked from mirrors/bookwyrm
Track completed items on job
This commit is contained in:
parent
9e673834dc
commit
47b98ad0d9
3 changed files with 44 additions and 2 deletions
|
@ -126,6 +126,7 @@ def import_item_task(item_id):
|
|||
except Exception as err: # pylint: disable=broad-except
|
||||
item.fail_reason = _("Error loading book")
|
||||
item.save()
|
||||
item.update_job()
|
||||
raise err
|
||||
|
||||
if item.book:
|
||||
|
@ -135,6 +136,7 @@ def import_item_task(item_id):
|
|||
item.fail_reason = _("Could not find a match for book")
|
||||
|
||||
item.save()
|
||||
item.update_job()
|
||||
|
||||
|
||||
def handle_imported_book(item):
|
||||
|
@ -144,6 +146,8 @@ def handle_imported_book(item):
|
|||
if isinstance(item.book, models.Work):
|
||||
item.book = item.book.default_edition
|
||||
if not item.book:
|
||||
item.fail_reason = _("Error loading book")
|
||||
item.save()
|
||||
return
|
||||
if not isinstance(item.book, models.Edition):
|
||||
item.book = item.book.edition
|
||||
|
|
32
bookwyrm/migrations/0116_auto_20211114_1700.py
Normal file
32
bookwyrm/migrations/0116_auto_20211114_1700.py
Normal file
|
@ -0,0 +1,32 @@
|
|||
# Generated by Django 3.2.5 on 2021-11-14 17:00
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.utils.timezone
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('bookwyrm', '0115_importitem_linked_review'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='importjob',
|
||||
name='complete',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='importjob',
|
||||
name='task_id',
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='importjob',
|
||||
name='completed_count',
|
||||
field=models.IntegerField(default=0),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='importjob',
|
||||
name='updated_date',
|
||||
field=models.DateTimeField(default=django.utils.timezone.now),
|
||||
),
|
||||
]
|
|
@ -35,10 +35,10 @@ class ImportJob(models.Model):
|
|||
|
||||
user = models.ForeignKey(User, on_delete=models.CASCADE)
|
||||
created_date = models.DateTimeField(default=timezone.now)
|
||||
task_id = models.CharField(max_length=100, null=True) # TODO: deprecated
|
||||
include_reviews = models.BooleanField(default=True)
|
||||
mappings = models.JSONField()
|
||||
complete = models.BooleanField(default=False)
|
||||
updated_date = models.DateTimeField(default=timezone.now)
|
||||
completed_count = models.IntegerField(default=0)
|
||||
source = models.CharField(max_length=100)
|
||||
privacy = models.CharField(
|
||||
max_length=255, default="public", choices=PrivacyLevels.choices
|
||||
|
@ -66,6 +66,12 @@ class ImportItem(models.Model):
|
|||
"Review", on_delete=models.SET_NULL, null=True, blank=True
|
||||
)
|
||||
|
||||
def update_job(self):
|
||||
"""this user is here! they are doing things!"""
|
||||
self.job.completed_count += 1
|
||||
self.job.updated_date = timezone.now()
|
||||
self.job.save()
|
||||
|
||||
def resolve(self):
|
||||
"""try various ways to lookup a book"""
|
||||
# we might be calling this after manually adding the book,
|
||||
|
|
Loading…
Reference in a new issue