-K allows to specify which apps to cron, thanks Jonathan

This commit is contained in:
mdipierro
2012-07-08 20:28:09 -05:00
parent d0463c05b2
commit a02644c39e
4 changed files with 38 additions and 24 deletions
+1 -1
View File
@@ -1 +1 @@
Version 2.00.0 (2012-07-08 17:39:33) dev
Version 2.00.0 (2012-07-08 20:28:04) dev
+9 -7
View File
@@ -43,16 +43,17 @@ def stopcron():
class extcron(threading.Thread):
def __init__(self, applications_parent):
def __init__(self, applications_parent, apps=None):
threading.Thread.__init__(self)
self.setDaemon(False)
self.path = applications_parent
# crondance(self.path, 'external', startup=True)
self.apps = apps
# crondance(self.path, 'external', startup=True, apps=self.apps)
def run(self):
if not _cron_stopping:
logger.debug('external cron invocation')
crondance(self.path, 'external', startup=False)
crondance(self.path, 'external', startup=False, apps=self.apps)
class hardcron(threading.Thread):
@@ -80,7 +81,7 @@ class softcron(threading.Thread):
def __init__(self, applications_parent):
threading.Thread.__init__(self)
self.path = applications_parent
crondance(self.path, 'soft', startup=True)
# crondance(self.path, 'soft', startup=True)
def run(self):
if not _cron_stopping:
@@ -242,7 +243,7 @@ class cronlauncher(threading.Thread):
logger.debug('WEB2PY CRON Call returned success:\n%s' \
% stdoutdata)
def crondance(applications_parent, ctype='soft', startup=False):
def crondance(applications_parent, ctype='soft', startup=False, apps=None):
apppath = os.path.join(applications_parent,'applications')
cron_path = os.path.join(applications_parent)
token = Token(cron_path)
@@ -256,8 +257,9 @@ def crondance(applications_parent, ctype='soft', startup=False):
('dom',now_s.tm_mday),
('dow',(now_s.tm_wday+1)%7))
apps = [x for x in os.listdir(apppath)
if os.path.isdir(os.path.join(apppath, x))]
if apps is None:
apps = [x for x in os.listdir(apppath)
if os.path.isdir(os.path.join(apppath, x))]
full_apath_links = set()
+21 -15
View File
@@ -911,14 +911,6 @@ def start(cron=True):
test(options.test, verbose=options.verbose)
return
# ## if -K
if options.scheduler:
try:
start_schedulers(options)
except KeyboardInterrupt:
pass
return
# ## if -S start interactive shell (also no cron)
if options.shell:
if not options.args is None:
@@ -928,21 +920,35 @@ def start(cron=True):
return
# ## if -C start cron run (extcron) and exit
# ## if -N or not cron disable cron in this *process*
# ## if --softcron use softcron
# ## use hardcron in all other cases
# ## -K specifies optional apps list (overloading scheduler)
if options.extcron:
print 'Starting extcron...'
logger.debug('Starting extcron...')
global_settings.web2py_crontype = 'external'
extcron = newcron.extcron(options.folder)
if options.scheduler: # -K
apps = [app.strip() for app in options.scheduler.split(',')]
else:
apps = None
extcron = newcron.extcron(options.folder, apps=apps)
extcron.start()
extcron.join()
return
elif cron and not options.nocron and options.softcron:
# ## if -K
if options.scheduler:
try:
start_schedulers(options)
except KeyboardInterrupt:
pass
return
# ## if -N or not cron disable cron in this *process*
# ## if --softcron use softcron
# ## use hardcron in all other cases
if cron and not options.nocron and options.softcron:
print 'Using softcron (but this is not very efficient)'
global_settings.web2py_crontype = 'soft'
elif cron and not options.nocron:
print 'Starting hardcron...'
logger.debug('Starting hardcron...')
global_settings.web2py_crontype = 'hard'
newcron.hardcron(options.folder).start()
+7 -1
View File
@@ -29,7 +29,7 @@
# set to DEBUG.
[loggers]
keys=root,rocket,markdown,web2py,rewrite,app,welcome
keys=root,rocket,markdown,web2py,rewrite,cron,app,welcome
[handlers]
keys=consoleHandler,messageBoxHandler
@@ -55,6 +55,12 @@ qualname=web2py.rewrite
handlers=consoleHandler
propagate=0
[logger_cron]
level=WARNING
qualname=web2py.cron
handlers=consoleHandler
propagate=0
# generic app handler
[logger_app]
level=WARNING