Added tasks app
This commit is contained in:
parent
89f38df733
commit
83208fa093
|
@ -41,11 +41,12 @@ def get_tasks(manage):
|
||||||
sys.stderr.write("I am unable to connect to the database\n")
|
sys.stderr.write("I am unable to connect to the database\n")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
script, settings_file = sys.argv[:2]
|
script, settings_file = sys.argv[:2]
|
||||||
|
enabled = 1 if 'sqlite' in settings['ENGINE'] else True
|
||||||
query = (
|
query = (
|
||||||
"SELECT c.minute, c.hour, c.day_of_week, c.day_of_month, c.month_of_year, p.id "
|
"SELECT c.minute, c.hour, c.day_of_week, c.day_of_month, c.month_of_year, p.id "
|
||||||
"FROM djcelery_periodictask as p, djcelery_crontabschedule as c "
|
"FROM djcelery_periodictask as p, djcelery_crontabschedule as c "
|
||||||
"WHERE p.crontab_id = c.id AND p.enabled = True"
|
"WHERE p.crontab_id = c.id AND p.enabled = {}"
|
||||||
)
|
).format(enabled)
|
||||||
tasks = db.run_query(conn, query)
|
tasks = db.run_query(conn, query)
|
||||||
conn.close()
|
conn.close()
|
||||||
return tasks
|
return tasks
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
import ast
|
|
||||||
|
|
||||||
from django import db
|
from django import db
|
||||||
|
|
||||||
|
|
||||||
|
@ -19,25 +17,23 @@ def close_connection(execute):
|
||||||
|
|
||||||
def get_settings(settings_file):
|
def get_settings(settings_file):
|
||||||
""" get db settings from settings.py file without importing """
|
""" get db settings from settings.py file without importing """
|
||||||
settings = {}
|
settings = {'__file__': settings_file}
|
||||||
with open(settings_file, 'r') as handler:
|
with open(settings_file) as f:
|
||||||
body = ast.parse(handler.read()).body
|
__file__ = 'rata'
|
||||||
for var in body:
|
exec(f.read(), settings)
|
||||||
targets = getattr(var, 'targets', None)
|
settings = settings['DATABASES']['default']
|
||||||
if targets and targets[0].id == 'DATABASES':
|
if settings['ENGINE'] not in ('django.db.backends.sqlite3', 'django.db.backends.postgresql_psycopg2'):
|
||||||
keys = var.value.values[0].keys
|
raise ValueError("%s engine not supported." % settings['ENGINE'])
|
||||||
values = var.value.values[0].values
|
return settings
|
||||||
for key, value in zip(keys, values):
|
|
||||||
if key.s == 'ENGINE':
|
|
||||||
if value.s not in ('django.db.backends.sqlite3', 'django.db.backends.postgresql_psycopg2'):
|
|
||||||
raise ValueError("%s engine not supported." % value)
|
|
||||||
settings[key.s] = getattr(value, 's', None)
|
|
||||||
return settings
|
|
||||||
|
|
||||||
|
|
||||||
def get_connection(settings):
|
def get_connection(settings):
|
||||||
import psycopg2
|
if settings['ENGINE'] == 'django.db.backends.sqlite3':
|
||||||
conn = psycopg2.connect("dbname='{NAME}' user='{USER}' host='{HOST}' password='{PASSWORD}'".format(**settings))
|
import sqlite3
|
||||||
|
return sqlite3.connect(settings['NAME'])
|
||||||
|
elif settings['ENGINE'] == 'django.db.backends.postgresql_psycopg2':
|
||||||
|
import psycopg2
|
||||||
|
return psycopg2.connect("dbname='{NAME}' user='{USER}' host='{HOST}' password='{PASSWORD}'".format(**settings))
|
||||||
return conn
|
return conn
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue