Files
django-q2/django_q/signals.py
T
Ilan Steemers 15155c7a99 Build improvements (#569)
* Black linting

* Adding Black to dev dependencies and upping minimal python to 3.6.2 for compatibility

* Updating packages

* Removing pip-tools input and exporting requirements with poetry

* Deleting old setup files and test runner

* Trying 1.3.7

* Looser extras requirements to prevent conflicts

* Sorted imports with isort

* Added iSort to dev dependencies

* Fixes localtime for naive setups
2021-05-30 17:10:07 +02:00

40 lines
1.1 KiB
Python

import importlib
from django.db.models.signals import post_save
from django.dispatch import Signal, receiver
from django.utils.translation import gettext_lazy as _
from django_q.conf import logger
from django_q.models import Task
@receiver(post_save, sender=Task)
def call_hook(sender, instance, **kwargs):
if instance.hook:
f = instance.hook
if not callable(f):
try:
module, func = f.rsplit(".", 1)
m = importlib.import_module(module)
f = getattr(m, func)
except (ValueError, ImportError, AttributeError):
logger.error(
_(f"malformed return hook '{instance.hook}' for [{instance.name}]")
)
return
try:
f(instance)
except Exception as e:
logger.error(
_(
f"return hook {instance.hook} failed on [{instance.name}] because {str(e)}"
)
)
# args: task
pre_enqueue = Signal()
# args: func, task
pre_execute = Signal()