Commit 691a31b6 authored by Matheus Miranda's avatar Matheus Miranda
Browse files

Fix revoke for previous tasks

parent 18bc708f
......@@ -15,19 +15,19 @@ def lesson_created_or_updated(sender, instance: Lesson, **kwargs):
previous_lesson = Lesson.objects.get(id=instance.id)
if (not instance.id or instance.release_date != previous_lesson.release_date) and instance.release_date:
previous_task_hask = ''
previous_task_hash = ''
ct = ContentType.objects.get_for_model(instance)
st = ScheduledTask.objects.filter(content_type=ct, object_id=instance.id)
if st.exists():
st = st.first()
previous_task_hask = st.task_hash
previous_task_hash = st.task_hash
else:
st = ScheduledTask.objects.create(content_object=instance)
if previous_task_hask:
res = AsyncResult(previous_task_hask)
res.revoke()
if previous_task_hash:
from celery.task.control import revoke
revoke(previous_task_hash)
new_task_hash = publish_lesson.apply_async(args=[instance.id], eta=instance.release_date)
st.task_hash = new_task_hash
......@@ -35,7 +35,6 @@ def lesson_created_or_updated(sender, instance: Lesson, **kwargs):
st.release_date = instance.release_date
st.save()
@receiver(pre_save, sender=Unit)
def unit_created_or_updated(sender, instance: Unit, **kwargs):
previous_unit = Unit.objects.get(id=instance.id)
......
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