Django Celery Database for Models on Producer and Worker -


i want develop application uses django fronted , celery background stuff. now, celery workers on different machines need database access django frontend machine (two different servers). need know realtime stuff , run django-app

python manage.py celeryd  

they need access database models available.

do have access mysql database through direct connection? have allow user "my-django-app" access not localhost on frontend machine other worker server ips?

is "right" way, or i'm missing something? thought isn't safe (without ssl), maybe that's way has be.

thanks responses!

they need access database. access through database backend, can 1 ships django or one third party.

one thing i've done in django site's settings.py load database access info file in /etc. way access setup (database host, port, username, password) can different each machine, , sensitive info password isn't in project's repository. might want restrict access workers in similar manner, making them connect different username.

you pass in database connection information, or key or path configuration file, via environment variables, , handle in settings.py.

for example, here's how pull in database configuration file:

g = {} dbsetup = {} execfile(os.environ['db_config'], g, dbsetup) if 'databases' in dbsetup:     databases = dbsetup['databases'] else:     databases = {         'default': {             'engine': 'django.db.backends.mysql',             # ...         }     } 

needless say, need make sure file in db_config not accessible user besides db admins , django itself. default case should refer django developer's own test database. there may better solution using ast module instead of execfile, haven't researched yet.

another thing use separate users db admin tasks vs. else. in manage.py, added following preamble:

# find database configuration, if there one, , set in environment. admindbconffile = '/etc/django/db_admin.py' dbconffile = '/etc/django/db_regular.py' import sys import os def goodfile(path):     return os.path.isfile(path) , os.access(path, os.r_ok) if len(sys.argv) >= 2 , sys.argv[1] in ["syncdb", "dbshell", "migrate"] \     , goodfile(admindbconffile):     os.environ['db_config'] = admindbconffile elif goodfile(dbconffile):     os.environ['db_config'] = dbconffile 

where config in /etc/django/db_regular.py user access django database select, insert, update, , delete, , /etc/django/db_admin.py user these permissions plus create, drop, index, alter, , lock tables. (the migrate command south.) gives me protection django code messing schema @ runtime, , limits damage sql injection attack can cause (though should still check , filter user input).

this isn't solution exact problem, might give ideas ways smarten django's database access setup purposes.


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -