Ticket #2406: runjobs.patch

File runjobs.patch, 2.5 KB (added by ian@…, 18 years ago)

patch to implement the 'runjobs' functionality

  • management.py

     
    11371137    runfastcgi(args)
    11381138runfcgi.args = '[various KEY=val options, use `runfcgi help` for help]'
    11391139
     1140def runjobs(which=None):
     1141    "Runs scheduled maintenance operations defined by the installed applications"
     1142    from django.core import signals
     1143    from django.db import models
     1144    from django.dispatch import dispatcher
     1145    from django.conf import settings
     1146   
     1147    if which is None or which == 'help':
     1148        print "run scheduled maintenance operations. Please specify 'hourly', 'daily', 'weekly' or 'monthly' "
     1149    else:
     1150        for app_name in settings.INSTALLED_APPS:
     1151            try:
     1152                __import__(app_name + '.management', '', '', [''])
     1153            except ImportError:
     1154                pass
     1155
     1156        for app in models.get_apps():
     1157
     1158            if which == 'hourly':
     1159                dispatcher.send(signal=signals.run_hourly_jobs, sender=app, app=app)
     1160            elif which == 'daily':
     1161                dispatcher.send(signal=signals.run_daily_jobs, sender=app, app=app)
     1162            elif which == 'weekly':
     1163                dispatcher.send(signal=signals.run_weekly_jobs, sender=app, app=app)
     1164            elif which == 'monthly':
     1165                dispatcher.send(signal=signals.run_monthly_jobs, sender=app, app=app)
     1166
     1167
     1168
     1169
     1170runjobs.args="[hourly daily weekly monthly]"
     1171runjobs.help_doc = "Runs scheduled maintenance operations defined by the installed applications"
     1172
     1173
    11401174# Utilities for command-line script
    11411175
    11421176DEFAULT_ACTION_MAPPING = {
     
    11491183    'reset': reset,
    11501184    'runfcgi': runfcgi,
    11511185    'runserver': runserver,
     1186    'runjobs': runjobs,
    11521187    'shell': run_shell,
    11531188    'sql': get_sql_create,
    11541189    'sqlall': get_sql_all,
     
    12711306        action_mapping[action](addr, port, options.use_reloader)
    12721307    elif action == 'runfcgi':
    12731308        action_mapping[action](args[1:])
     1309
     1310    elif action == 'runjobs':
     1311        action_mapping[action](args[1])
    12741312    else:
    12751313        from django.db import models
    12761314        try:
  • signals.py

     
    11request_started = object()
    22request_finished = object()
    33got_request_exception = object()
     4run_hourly_jobs=object()
     5run_daily_jobs=object()
     6run_weekly_jobs=object()
     7run_monthly_jobs=object()
Back to Top