I would like to update my model object once a celery task has completed. I am currently at a loss about how to go about doing this though.
Here is a layout of the files
from photos.tasks import photo_download
class Photo(models.Model):
....fields....
@receiver(post_save)
def download_photo_callback(sender, **kwargs):
photo = kwargs["instance"]
result = photo_download.delay(photo.uid)
from photo.models import Photo
@task()
def photo_download(photo_uid, callback=None):
...do stuff...
photo.status = 'D'
photo.save()
You're doing a circular import. Your tasks.py
file is importing your models.py
file and vice-versa. You should move your signals to a separate signals.py
file to avoid it.
There is an example in documentation:
http://docs.celeryproject.org/en/latest/userguide/tasks.html#example
See spam_filter task:
http://docs.celeryproject.org/en/latest/userguide/tasks.html#blog-tasks-py
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With