2

Catch django signal sent from celery task. Is it possible? As far as I know they are running in different processes

@celery.task
def my_task():
    ...
    custom_signal.send()

@receiver(custom_signal)
def my_signal_handler():
    ...
timKa
  • 167
  • 2
  • 9

1 Answers1

0

Please take in mind that your async task must be @shared_task decorator. in order to be called from outside since it will not be attached to a concrete app instance. Documentation @shared_task celery

task.py

@shared_task
def send_email(email):
    # Do logic for sending email or other task

signal.py

as you can see below this will only execute when post_save (After user executes save) for the model Contract in your case would be anyother model that its being executed.

@receiver(post_save, sender=Contract)
def inflation_signal(sender, **kwargs):
    if kwargs['created']:
        send_email.delay('mymail@example.com')
Eddwin Paz
  • 2,842
  • 4
  • 28
  • 48
  • 1
    It looks like you don't understand me. I mean sending signal from celery task to django, not otherwise – timKa Nov 28 '18 at 08:08
  • @timKa Did you ever find an answer that worked? I looking for the same thing. – MikeyE Apr 17 '23 at 07:54