Use signals for website celery tasks

This commit is contained in:
Jan Dittberner 2023-04-17 19:41:42 +02:00
parent 8e42cb9c18
commit 9fbd608837
5 changed files with 158 additions and 47 deletions

View file

@ -18,7 +18,7 @@ class ManageMailsAppConfig(AppConfig):
def ready(self):
"""
Takes care of importing the signal handlers of the :py:mod:`userdbs`
Takes care of importing the signal handlers of the :py:mod:`managemails`
app.
"""

View file

@ -31,14 +31,16 @@ def handle_mailbox_created(sender, instance, created, **kwargs):
"""
if created:
taskresult = TaskResult.objects.create_task_result(
task_result = TaskResult.objects.create_task_result(
"handle_mailbox_created",
create_file_mailbox.s(instance.osuser.username, instance.username),
)
_LOGGER.info(
"Mailbox creation has been requested in task %s", taskresult.task_id
"Mailbox creation has been requested in task %s", task_result.task_id
)
_LOGGER.debug("mailbox %s has been %s", instance, created and "created" or "updated")
_LOGGER.debug(
"mailbox %s has been %s", instance, created and "created" or "updated"
)
@receiver(post_delete, sender=Mailbox)
@ -53,10 +55,8 @@ def handle_mailbox_deleted(sender, instance, **kwargs):
This signal handler starts a Celery_ task.
"""
taskresult = TaskResult.objects.create_task_result(
task_result = TaskResult.objects.create_task_result(
"handle_mailbox_deleted",
delete_file_mailbox.s(instance.osuser.username, instance.username)
)
_LOGGER.info(
"Mailbox deletion has been requested in task %s", taskresult.task_id
delete_file_mailbox.s(instance.osuser.username, instance.username),
)
_LOGGER.info("Mailbox deletion has been requested in task %s", task_result.task_id)