portier/source/concierge/signals.py

13 lines
550 B
Python

from django.dispatch import receiver
from .models import Task
from config.signals_shared import stream_inactive
from config.models import Stream
@receiver(stream_inactive)
def delete_tasks_when_stream_inactive(sender, **kwargs):
# when a stream has become inactive, all related tasks which are created for the stream need to be deleted.
# we need to exclude the pull tasks, as they are not created for the stream.
stream = Stream.objects.get(stream=kwargs['stream'])
Task.objects.filter(stream=stream).exclude(type="pull").delete()