Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
MOOC packages by hacklab
django-courses
Commits
691a31b6
Commit
691a31b6
authored
Dec 07, 2021
by
Matheus Miranda
Browse files
Fix revoke for previous tasks
parent
18bc708f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
6 deletions
+5
-6
courses/signals.py
courses/signals.py
+5
-6
No files found.
courses/signals.py
View file @
691a31b6
...
...
@@ -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_has
k
=
''
previous_task_has
h
=
''
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_has
k
=
st
.
task_hash
previous_task_has
h
=
st
.
task_hash
else
:
st
=
ScheduledTask
.
objects
.
create
(
content_object
=
instance
)
if
previous_task_has
k
:
res
=
AsyncResult
(
previous_task_hask
)
res
.
revoke
()
if
previous_task_has
h
:
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
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment