librelist archives

« back to archive

Best practices: flask and celery custom classes

Best practices: flask and celery custom classes

From:
Viacheslav Biriukov
Date:
2014-02-14 @ 20:25
Hi guys!

There is a snippet in documentation, that explains how to use application
context with celery tasks: http://flask.pocoo.org/docs/patterns/celery/.

But what is the best practice if you want to use Celery custom tasks. For
example I have several task's classes for doing some different stuff. So I
use following decorators:

@celery.task(base=SomeApiCall)
def some_api_call():
    pass

@celery.task(base=SomePictureResizing)
def some_picture_resizing():
   pass

How to be in this cases if I want to have application context in all of
this tasks?
What if I want to have an application context not only in __call__() but
also in after_return() and success()  Celery stages?

Thank you!

-- 
Viacheslav Biriukov
BR
http://biriukov.me