From a02644c39ee46ee8e15e6b808bd6449d9ac511de Mon Sep 17 00:00:00 2001 From: mdipierro Date: Sun, 8 Jul 2012 20:28:09 -0500 Subject: [PATCH] -K allows to specify which apps to cron, thanks Jonathan --- VERSION | 2 +- gluon/newcron.py | 16 +++++++++------- gluon/widget.py | 36 +++++++++++++++++++++--------------- logging.example.conf | 8 +++++++- 4 files changed, 38 insertions(+), 24 deletions(-) diff --git a/VERSION b/VERSION index 53517239..16682a72 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -Version 2.00.0 (2012-07-08 17:39:33) dev +Version 2.00.0 (2012-07-08 20:28:04) dev diff --git a/gluon/newcron.py b/gluon/newcron.py index 1c082347..1b6fb689 100644 --- a/gluon/newcron.py +++ b/gluon/newcron.py @@ -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() diff --git a/gluon/widget.py b/gluon/widget.py index dfa2cb99..6a7c823d 100644 --- a/gluon/widget.py +++ b/gluon/widget.py @@ -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() diff --git a/logging.example.conf b/logging.example.conf index 79b7272d..ac365aa1 100644 --- a/logging.example.conf +++ b/logging.example.conf @@ -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