Commit aaa620fb authored by Matheus Miranda's avatar Matheus Miranda
Browse files

Change syntax for new celery version

parent d0f4ab6d
......@@ -6,6 +6,8 @@ from .tasks import publish_lesson, publish_unit
from .scheduling.models import ScheduledTask
from celery.result import AsyncResult
from celery import Celery
app = Celery()
def schedule_task(content_type, instance):
......@@ -18,8 +20,7 @@ def schedule_task(content_type, instance):
previous_task_hash = st.task_hash
if previous_task_hash:
from celery.task.control import revoke
revoke(previous_task_hash)
app.control.revoke(previous_task_hash)
if content_type.name == 'Lesson':
new_task_hash = publish_lesson.apply_async(args=[instance.id], eta=instance.release_date)
......@@ -33,25 +34,27 @@ def schedule_task(content_type, instance):
@receiver(pre_save, sender=Lesson)
def pre_lesson_created_or_updated(sender, instance: Lesson, **kwargs):
previous_release_date = None
prev_release_date = None
prev_release_date_tz = 'UTC'
if instance.id:
previous_lesson = Lesson.objects.get(id=instance.id)
previous_release_date = previous_lesson.release_date
prev_release_date = previous_lesson.release_date
prev_release_date_tz = previous_lesson.release_date_timezone
if instance.release_date and instance.release_date_timezone:
import pytz
tz = pytz.timezone(instance.release_date_timezone)
instance.release_date = instance.release_date.replace(tzinfo=tz)
import pytz
tz = pytz.timezone(instance.release_date_timezone)
instance.release_date = instance.release_date.astimezone(tz)
new_release_date = instance.release_date
new_release_date_tz = instance.release_date_timezone
if new_release_date:
new_release_date = new_release_date.replace(microsecond=0, second=0)
if previous_release_date:
previous_release_date = previous_release_date.replace(microsecond=0, second=0)
if prev_release_date:
prev_release_date = prev_release_date.replace(microsecond=0, second=0)
if (not instance.id or new_release_date != previous_release_date) \
and instance.release_date:
if (not instance.id or new_release_date != prev_release_date or new_release_date_tz != prev_release_date_tz) \
and instance.release_date and instance.release_date_timezone:
from django.contrib.contenttypes.models import ContentType
content_type = ContentType.objects.get_for_model(instance)
......
from .models import Lesson, Unit
from celery.decorators import task
#fro celery.decorators import task
from celery import Celery
app = Celery()
@task()
@app.task()
def publish_lesson(object_id):
lesson = Lesson.objects.filter(id=object_id)
if lesson.exists():
......@@ -10,7 +12,7 @@ def publish_lesson(object_id):
lesson.status = 'published'
lesson.save()
@task()
@app.task()
def publish_unit(object_id):
unit = Unit.objects.filter(id=object_id)
if unit.exists():
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment