Re: [flask] Using application context in rq worker
- Michael Graupner
- 2015-03-11 @ 08:05
I already knew about the with app.app_context(): part but could not figure
out how to get the context into the worker... After your answer I looked at
how flask-rq is doing it (I did not want to use it because it was not
updated since 2 years and I try to avoid old unmaintained add-ons) and
finally found a clue in this stackoverflow question:
After getting the imports of the app right (from manage import app) and
setting the worker path of rqworker to my applications directory everything
works as expected.
2015-03-10 18:34 GMT+01:00 Jonathan Chen <email@example.com>:
> You can take a look at the project called flask-rq for some more help. In
> general though you'll need to pass the context of the object with your jobs
> in order for it to work correctly. You'll still need to do something
> similar in the following:
> def random():
> with app.app_context():
> x = 1 + 1
> Jonathan C.
> Vice President of IT | Sunrider International
> On Tue, Mar 10, 2015 at 9:55 AM, Michael Graupner <firstname.lastname@example.org>
>> I'm having problems using the application context of the flask app in a
>> rq worker (http://python-rq.org/).
>> My application structure is the one used by Miguel Grinbergs flasky app:
>> The only place where the app object exists is the manage.py and I don't
>> know how to access this from the workers perspective or how to initialize
>> a worker with the app context. Could someone give me a little hint or show
>> me some examle code how to do this properly? The goald should be the
>> creaetion of database entries with the database connection from the app
>> context, accessing the url router and using the template engine in the
>> Thanks for your help.
> CONFIDENTIALITY NOTICE: This message is intended only for the use of
the individual or entity to which it is addressed, and may contain
information that is privileged, confidential, and exempt from disclosure
under applicable law. If you have received this email in error, please
immediately notify the sender by return email and delete this email and
any attachments from your system.