Conversation
jeanphix
commented
Oct 26, 2012
- removes the circular dependency between app and RQ instance
- helpers are now module to level member
- adds DSN configuration for queues
- doc reflect changes
- tests
- travisci integration
… rq - please use get_queue().enqueue()
Wow. I'm rather busy today but I can't wait to review all this.
|
did you guys manage to make it work? sorry i'm quite a newb in flask. When I'm trying to use the models from my App (with SQLAlchemy), i got either 'working outside of application context' or 'application not registered on db instance and no application bound to current context'. I can't figure out a way to make the job functions recognize the application context. It would be great if you can help. Thanks |
@nguyenchiencong You should consider creating an issue for that with minimal code... For sure it works just fine with sqlalchemy objects. |
hi @jeanphix the problem is not with this particular project. I tried to use only rq, and still have the same problem. I think it might be because of how I organize my folders and declare the models in the Flask App. I'm so used to the autoloads of Rails. thanks |
@nguyenchiencong You need to create an app context in your tasks since they are executed outside the context of a request. You can do this as such: @rq.task
def my_task():
with app.app_context():
MyModel.query.filter(....) |
@jeanphix Can you explain your changes here a bit more? I don't see any practical examples in the tests for the helper functions. Also, most extensions also register themselves on the application and you seem to have removed that. |
@mattupstate The README is up to date with examples, also commit titles explain what have been done. |
Any idea if the redis python library is thread safe? Upon further inspection the module level functions all end up calling from flask import Flask
from flask_rq import task
app = Flask(__name__)
@task
def my_task():
# long runing task
@app.route('/')
def index():
my_task()
return "response..." If I'm following your code correctly the above would fail. I very well could be wrong though. |
Thanks @mattupstate |
Your example code can't work at all cause we can't enqueue main module function call. Anyway, I've fixed the decorator that can now decorate function outside flask app context. Maybe it should be called @job instead of @task and mimic the one include in rq. I mean with timeout option. Let me know. Cheers, |
@jeanphix This looks a lot better. One thing that is missing is that the RQ constructor needs to be able to be called without passing any arguments to it. Its a standard pattern for Flask extensions. |
@mattupstate Fixed. You didn't answer about renaming |
Go ahead and change it to |
@mattupstate Done |
Merge @jeanphix's changes to drastically improve extension
Thanks so much. I've uploaded the new release to PyPi |