0

I have installed django easy-thumbanils 2.2. It has worked well up to now, but I decided to make it asynchronous to improve performance. Following the docs, I implemented the following code:

models.py

#saved_file.connect(generate_aliases_global) -> Code used for synchronous operation
@receiver(saved_file)
def generate_thumbnails_async(sender, fieldfile, **kwargs):
print('Calling') #This is being called during an upload
tasks.add.delay(10,2) # A Test function in tasks.py. Confirmed it is being called and the result outputted by the worker
tasks.generate_thumbnails.delay(
        model=sender, pk=fieldfile.instance.pk,
        field=fieldfile.field.name) #this function not called????

tasks.py

from easy_thumbnails.files import generate_all_aliases

@task
def generate_thumbnails(model, pk, field):
    print('Calling gen_thumb task') #not called from models.py
    instance = model._default_manager.get(pk=pk)
    fieldfile = getattr(instance, field)
    generate_all_aliases(fieldfile, include_global=True)

@shared_task
def add(x, y):
    print('Calling ad task') #Called from models.py 
    return x + y

Why is it that the add task is being called but not the generate_thumbnails task please?

RunLoop
  • 20,288
  • 21
  • 96
  • 151
  • The @task decorator needs to be bound to an app. The shared task does not. see here: http://docs.celeryproject.org/en/latest/django/first-steps-with-django.html#using-the-shared-task-decorator – Mark Galloway Jul 18 '15 at 09:48
  • @MarkGalloway Thanks, I tried that but it had no effect. I also restarted my worked and confirmed that the task has been registered, but it's still not being executed – RunLoop Jul 18 '15 at 11:06

0 Answers0