Loading Scheduler Configuration On-the-Fly

35 views
Skip to first unread message

Bryan Chance

unread,
Jun 4, 2018, 2:55:42 PM6/4/18
to web2py-users
So I'm working to consolidate severall web2py apps that share ~85% of their code. They each have their own configurations, databases, etc.

I accomplish this by using routes.py to map myurl.com/client_name to myurl.com/consolidated_app?client_name=client_name

Then request.vars.client_name allows me to load client-specific db uris, models_to_run, etc. Now I need a way to do a similar thing with the scheduler. Since the request doesn't go the way http requests do, I can't load the "environment" to look the way for task for CllientA the way it would look for browsing myurl.com/ClientA.

The only other way I can think to solve this would be to pass all needed data to queue_task and then create new db connections there. But then I run into the issue of the models won't be loaded as expected.

Does anyone have any ideas?

Bryan Chance

unread,
Jun 4, 2018, 4:18:45 PM6/4/18
to web2py-users
I believe I might be able to queue the task with application set to the context I want it ran in, and then in db.py set request.vars.client to request.application

Dave S

unread,
Jun 4, 2018, 8:02:53 PM6/4/18
to web2py-users


On Monday, June 4, 2018 at 1:18:45 PM UTC-7, Bryan Chance wrote:
I believe I might be able to queue the task with application set to the context I want it ran in, and then in db.py set request.vars.client to request.application

I only set default application in my routes.py, so my results may not match yours, but inside your scheduler handler code (the model file), doesn't request.application show the right value?

/dps
 

Massimo Di Pierro

unread,
Jun 14, 2018, 9:55:49 PM6/14/18
to web2py-users
You have to crate a function that given the request.vars.client_name creates the db object and calls the define_table's
In your model you have request.vars.client_name and you can call that function.
In your tasks you would call that function from your task with a parameter specfied when you enqueued the task.
Reply all
Reply to author
Forward
0 new messages