-
Notifications
You must be signed in to change notification settings - Fork 236
create_app twice? #13
Comments
I'm a little confused about this too. When I try the steps listed in the setup, I get an import error upon trying to run |
I was going to fork this and apply a hacky workaround, but I don't have the time to test it and the author might not want that. Anyway, given that I was experiencing the same problem with flask + celery 3 in my own app structure, I figured I'd share my workaround for the next person who googles and lands here. First, modify
Next in
This worked on my app structure with Celery 3.1.8. Hopefully this helps someone avoid the many hours I wasted dicking around with celery. If there's a better solution than this, I'd be happy to know. |
@joshpurvis Thats probably the best thing to do when it comes to the Celery app. There is not really any reason to have all the views/routes attached to the application in the context of the Celery app. At this point, the app just acts as a configuration and context lifecycle helper. |
@mattupstate can you update your celery example code to incorporate the changes from @joshpurvis (or your take on a fix for this)? I've spent some time working around the circular dependency that this project has, and the solution posted here works well. It would be helpful if this was in the project itself to save others from having to find or create a solution themselves. |
@joshpurvis THANK YOU SO MUCH :) I was wondering if there was a better way, but I think you have the best way. If you want more granularity to specify which one uses the task, I got it working be the methods below. It digs straight into the python files or the method/route I also the same problem. But I think you can do:
OR
Cheers! |
Hey, this is an issue I've been running into myself and trying to research it a bit I ran into your pretty nice base project!
to be able to give functions the annotation
@celery.task
we need to be able to import thecelery = Celery()
instance from somewhere.but to tie it together with all the Flask related stuff we want to be in app context (and I want to use the config from my app for some celery stuff too) so we need an instance of the app.
so you create that instance when creating the
Celery
instance ( I do the same in my project ).but this results in doing more
create_app
calls (or at least 1 more) when importing tasks to queue them from your blueprints.The thing is .. I'm not sure if it matters ... but it feels wrong ...
Just putting it here to discuss, hope you don't mind
The text was updated successfully, but these errors were encountered: