python - Dynamic per-request database connections in Django -


i'm building centralised django application interacting dynamic number of databases identical schema. these dbs used couple legacy applications, of in php. our solution avoid multiple silos of db credentials store info in generic setting files outside of respective applications. setting files created, altered or deleted without django application being restarted.

for every request django application, there http header or url parameter can used deduce setting file @ determine database credentials use.

my first thought use custom django middleware parse settings files (possibly caching) , create new connection object on each request, patching django.db before orm activity.

is there more graceful method handle situation? there thread safety issues should consider middleware approach?

rereading file heavy penalty pay when it's unlikely file has changed.

my usual approach use inotify watch configuration file changes, rather trying read file on every request. additionally, tend keep "current" configuration, parsed file, , replace new value once i've finished parsing config file , i'm it's valid. resolve of concerns thread safety setting current configuration on each incoming request, configuration can't change mid-way through request.


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -