Celery + Django Signals -
i trying leverage post_save function of django signals in combination celery tasks. after new message object saved database, want evaluate if instance has 1 of 2 attributes , if does, call 'send_sms_function' celery registered task.
tasks.py
from my_project.celery import app @app.task def send_sms_message(message): #
signals.py
from django.db.models.signals import post_save django.dispatch import receiver import rollbar rollbar.init('234...0932', 'production') dispatch.models import message comm.tasks import send_sms_message @receiver(post_save, sender=message) def send_outgoing_messages(sender, instance, **kwargs): if instance.some_attribute == 'a' or instance.some_attribute == 'b': try: send_sms_message.delay(instance) except: rollbar.report_exc_info() else: pass
i'm testing locally running celery worker. when in django shell , call celery function, works expected. when save message instance database, function not work expected: there nothing posted task queue , not see error messages.
what doing wrong?
the expression if instance.some_attribute == 'a' or 'b'
problem.
what mean is:
if instance.some_attribute == 'a' or instance.some_attribute == 'b'
or, how write it:
if instance.some_attribute in ('a', 'b')
Comments
Post a Comment