Skip to content

Commit

Permalink
Added a prefix to commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Pablo Caro Revuelta committed Apr 10, 2013
1 parent 676f049 commit ad36600
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
3 changes: 3 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ KRONOS_MANAGE
KRONOS_PYTHONPATH
Extra path which will be added as a ``--pythonpath`` option to the management command.

KRONOS_POSTFIX
Extra string added at the end of the command. For dirty thinks like '> /dev/null 2>&1'

Define these variables in your ``settings.py`` file if you wish to alter crontab lines.


Expand Down
12 changes: 8 additions & 4 deletions kronos/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
from version import __version__

import os
import sys

from functools import wraps

from kronos.utils import read_crontab, write_crontab, delete_crontab
Expand All @@ -13,6 +10,7 @@

tasks = []


def load():
"""
Load ``cron`` modules for applications listed in ``INSTALLED_APPS``.
Expand All @@ -35,18 +33,20 @@ def load():
except ImportError:
pass


def register(schedule):
def decorator(function):
global tasks

tasks.append(function)

function.cron_expression = '%(schedule)s %(python)s %(manage)s runtask %(task)s --settings=%(settings_module)s' % {
function.cron_expression = '%(schedule)s %(python)s %(manage)s runtask %(task)s --settings=%(settings_module)s %(postfix)s' % {
'schedule': schedule,
'python': KRONOS_PYTHON,
'manage': KRONOS_MANAGE,
'task': function.__name__,
'settings_module': settings.SETTINGS_MODULE,
'postfix': settings.KRONOS_POSTFIX
}
if KRONOS_PYTHONPATH is not None:
function.cron_expression += ' --pythonpath=%s' % KRONOS_PYTHONPATH
Expand All @@ -58,6 +58,7 @@ def wrapper(*args, **kwargs):

return decorator


def install():
"""
Register tasks with cron.
Expand All @@ -72,6 +73,7 @@ def install():

write_crontab(current_crontab + new_crontab)


def printtasks():
"""
Print the tasks that would be installed in the
Expand All @@ -82,6 +84,7 @@ def printtasks():
for task in tasks:
print task.cron_expression


def uninstall():
"""
Uninstall tasks from cron.
Expand All @@ -101,6 +104,7 @@ def uninstall():
else:
delete_crontab()


def reinstall():
uninstall()
install()
1 change: 1 addition & 0 deletions kronos/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
KRONOS_MANAGE = getattr(settings, 'KRONOS_MANAGE', '%s/manage.py' % os.getcwd())
KRONOS_PYTHONPATH = getattr(settings, 'KRONOS_PYTHONPATH', None)
PROJECT_MODULE = sys.modules['.'.join(settings.SETTINGS_MODULE.split('.')[:-1])]
KRONOS_POSTFIX = getattr(settings, 'KRONOS_POSTFIX', '')

0 comments on commit ad36600

Please sign in to comment.