From bb18610dd977b346276a79d5c542fa90a13c0368 Mon Sep 17 00:00:00 2001 From: Jan Koppe Date: Sun, 31 May 2020 15:20:22 +0200 Subject: [PATCH] fix: remove associated tasks when restreamconfig is deleted --- restream/signals.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/restream/signals.py b/restream/signals.py index 0ba466a..63ee256 100644 --- a/restream/signals.py +++ b/restream/signals.py @@ -33,3 +33,14 @@ def update_tasks(sender, **kwargs): task = Task(stream=instance.stream, type='restream', config_id=instance.id, configuration=instance.get_json_config()) task.save() + + +@receiver(pre_delete, sender=RestreamConfig) +def delete_tasks(sender, **kwargs): + instance = kwargs['instance'] + # Get the current task instance if it exists, and remove it + try: + task = Task.objects.filter(config_id=instance.id).get() + task.delete() + except Task.DoesNotExist: + pass