Comments (5)
@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:
from flask import current_app
if current_app: # if current app instance exists
from path.to.task import task
OR
def some_function(arg1,arg2):
from path.to.task import task
task.delay(arg1,arg2)
Cheers!
from overholt.
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 alembic upgrade head
. It appears that there is a circular dependency: create_app
tries to register all the blueprints, and the blueprints import celery tasks from tasks.py
. The celery instance in tasks.py is created by calling create_celery_app
, which then calls create_app
again. Is there a good way around this? Thanks
from overholt.
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 create_app
to include a new argument which toggles blueprints registration:
def create_app(register_blueprints=True):
app = Flask(__name__)
# ...
if register_blueprints:
from myblueprint.views import bp as myblueprint
app.register_blueprint(myblueprint)
Next in create_celery_app
, send register_blueprints=False
so that we don't try to register them when celery requests an app
, thus dodging the circular dependencies:
def create_celery_app(app=None):
app = app or create_app(register_blueprints=False)
# ...
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.
from overholt.
@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.
from overholt.
@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.
from overholt.
Related Issues (20)
- requirements.txt == versus >= HOT 1
- A question for core.Service HOT 7
- Authentication for Api HOT 1
- Cookies seem to contain successive registration emails. HOT 3
- Thoughts on imports HOT 3
- Where to discuss? Also next steps... HOT 2
- Where would I put signals? HOT 2
- How to use one service from another? HOT 1
- Overholt how to send the flask-security emails via Celery? HOT 4
- Deployment HOT 4
- Test suite hangs and never finishes successfully
- Service Objects vs Service Mixins HOT 4
- Trouble overriding default Flask-Security Forms
- How is the circular import of celery tasks handled? HOT 1
- decorative view function two times HOT 2
- celery context
- How to use Flask-Restful with this structure HOT 1
- Flask Principal within Overholt
- how to init database HOT 2
- potential decorator issue
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from overholt.