X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/b2c4c0093c7829668c1bf6f5a7493e1aff697181..2c101e78aee8cd3ccf3f24a0ecaa22fa77593c5c:/src/catalogue/management/commands/build_stale.py diff --git a/src/catalogue/management/commands/build_stale.py b/src/catalogue/management/commands/build_stale.py index b03e3e8e6..62ab73c60 100644 --- a/src/catalogue/management/commands/build_stale.py +++ b/src/catalogue/management/commands/build_stale.py @@ -1,5 +1,5 @@ -# This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later. -# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. +# This file is part of Wolne Lektury, licensed under GNU Affero GPLv3 or later. +# Copyright © Fundacja Wolne Lektury. See NOTICE for more information. # from time import time from django.conf import settings @@ -25,17 +25,20 @@ class Command(BaseCommand): def handle(self, **options): t = time() counter = 0 + tasks = [] while True: if options['time'] is not None and time() - t > options['time']: break if options['limit'] is not None and counter >= options['limit']: break - tasks = EbookField.find_all_stale(Book, 1) + if not tasks: + tasks = EbookField.find_all_stale(Book, options['limit'] or 100) if not tasks: break - for field_name, book in tasks: - print(field_name, book) - try: - getattr(book, field_name).build() - except Exception as e: - print('ERROR', e) + field_name, book = tasks.pop(0) + print(field_name, book) + counter += 1 + try: + getattr(book, field_name).build() + except Exception as e: + print('ERROR', e)