fix: remove associated tasks when restreamconfig is deleted

This commit is contained in:
Jan Koppe 2020-05-31 15:20:22 +02:00
parent 140186e608
commit bb18610dd9
Signed by: thunfisch
GPG Key ID: BE935B0735A2129B
1 changed files with 11 additions and 0 deletions

View File

@ -33,3 +33,14 @@ def update_tasks(sender, **kwargs):
task = Task(stream=instance.stream, type='restream', config_id=instance.id, task = Task(stream=instance.stream, type='restream', config_id=instance.id,
configuration=instance.get_json_config()) configuration=instance.get_json_config())
task.save() 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