From d04b366656def9a659889c0c83b07ccd0833fd5d Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Mon, 26 Sep 2022 12:46:19 +0200 Subject: [PATCH 1/1] celery fixes --- src/catalogue/fields.py | 25 +++++++++++++------------ src/club/models.py | 3 ++- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/catalogue/fields.py b/src/catalogue/fields.py index e177cd571..3d10cd8b8 100644 --- a/src/catalogue/fields.py +++ b/src/catalogue/fields.py @@ -10,7 +10,8 @@ from django.db.models.fields.files import FieldFile from catalogue import app_settings from catalogue.constants import LANGUAGES_3TO2, EBOOK_FORMATS_WITH_CHILDREN, EBOOK_FORMATS_WITHOUT_CHILDREN from catalogue.utils import absolute_url, remove_zip, truncate_html_words, gallery_path, gallery_url -from celery import Task, shared_task +#from celery import Task, shared_task +from celery.task import Task, task from celery.utils.log import get_task_logger from waiter.utils import clear_cache @@ -178,11 +179,11 @@ class BuildEbook(Task): if fieldfile.field.format_name in app_settings.FORMAT_ZIPS: remove_zip(app_settings.FORMAT_ZIPS[fieldfile.field.format_name]) # Don't decorate BuildEbook, because we want to subclass it. -BuildEbookTask = shared_task(BuildEbook, ignore_result=True) +BuildEbookTask = task(BuildEbook, ignore_result=True) @BuildEbook.register('txt') -@shared_task(ignore_result=True) +@task(ignore_result=True) class BuildTxt(BuildEbook): @staticmethod def transform(wldoc, fieldfile): @@ -190,7 +191,7 @@ class BuildTxt(BuildEbook): @BuildEbook.register('pdf') -@shared_task(ignore_result=True) +@task(ignore_result=True) class BuildPdf(BuildEbook): @staticmethod def transform(wldoc, fieldfile): @@ -204,7 +205,7 @@ class BuildPdf(BuildEbook): @BuildEbook.register('epub') -@shared_task(ignore_result=True) +@task(ignore_result=True) class BuildEpub(BuildEbook): librarian2_api = True @@ -218,7 +219,7 @@ class BuildEpub(BuildEbook): @BuildEbook.register('mobi') -@shared_task(ignore_result=True) +@task(ignore_result=True) class BuildMobi(BuildEbook): librarian2_api = True @@ -232,7 +233,7 @@ class BuildMobi(BuildEbook): @BuildEbook.register('html') -@shared_task(ignore_result=True) +@task(ignore_result=True) class BuildHtml(BuildEbook): def build(self, fieldfile): from django.core.files.base import ContentFile @@ -343,7 +344,7 @@ class BuildCover(BuildEbook): @BuildEbook.register('cover_clean') -@shared_task(ignore_result=True) +@task(ignore_result=True) class BuildCoverClean(BuildCover): @classmethod def transform(cls, wldoc, fieldfile): @@ -355,7 +356,7 @@ class BuildCoverClean(BuildCover): @BuildEbook.register('cover_thumb') -@shared_task(ignore_result=True) +@task(ignore_result=True) class BuildCoverThumb(BuildCover): @classmethod def transform(cls, wldoc, fieldfile): @@ -364,7 +365,7 @@ class BuildCoverThumb(BuildCover): @BuildEbook.register('cover_api_thumb') -@shared_task(ignore_result=True) +@task(ignore_result=True) class BuildCoverApiThumb(BuildCover): @classmethod def transform(cls, wldoc, fieldfile): @@ -373,7 +374,7 @@ class BuildCoverApiThumb(BuildCover): @BuildEbook.register('simple_cover') -@shared_task(ignore_result=True) +@task(ignore_result=True) class BuildSimpleCover(BuildCover): @classmethod def transform(cls, wldoc, fieldfile): @@ -382,7 +383,7 @@ class BuildSimpleCover(BuildCover): @BuildEbook.register('cover_ebookpoint') -@shared_task(ignore_result=True) +@task(ignore_result=True) class BuildCoverEbookpoint(BuildCover): @classmethod def transform(cls, wldoc, fieldfile): diff --git a/src/club/models.py b/src/club/models.py index acf131b12..ba4466b18 100644 --- a/src/club/models.py +++ b/src/club/models.py @@ -14,6 +14,7 @@ from django import template from django.utils.timezone import now from django.utils.translation import ugettext_lazy as _, ungettext, ugettext, get_language from django_countries.fields import CountryField +from pytz import utc from catalogue.utils import get_random_hash from messaging.states import Level from reporting.utils import render_to_pdf @@ -240,7 +241,7 @@ class Membership(models.Model): Contact = apps.get_model('messaging', 'Contact') if self.manual: - Contact.update(email, Level.MANUAL_MEMBER, self.updated_at) + Contact.update(email, Level.MANUAL_MEMBER, datetime.combine(self.updated_at, datetime.min.time(), utc)) else: Contact.reset(email) -- 2.20.1