diff --git a/VERSION b/VERSION index 0d37fbfc..49c1a8a3 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -Version 2.3.0 (2012-12-05 09:00:19) rc1 +Version 2.3.0 (2012-12-05 11:02:32) rc1 diff --git a/gluon/widget.py b/gluon/widget.py index 1f95efa7..70b399d2 100644 --- a/gluon/widget.py +++ b/gluon/widget.py @@ -1112,17 +1112,6 @@ def start(cron=True): pass return - # ## if -H cron is enabled in this *process* - # ## if --softcron use softcron - # ## use hardcron in all other cases - if cron and options.runcron and options.softcron: - print 'Using softcron (but this is not very efficient)' - global_settings.web2py_crontype = 'soft' - elif cron and options.runcron: - logger.debug('Starting hardcron...') - global_settings.web2py_crontype = 'hard' - newcron.hardcron(options.folder).start() - # ## if -W install/start/stop web2py as service if options.winservice: if os.name == 'nt': @@ -1137,6 +1126,17 @@ def start(cron=True): sys.exit(1) return + # ## if -H cron is enabled in this *process* + # ## if --softcron use softcron + # ## use hardcron in all other cases + if cron and options.runcron and options.softcron: + print 'Using softcron (but this is not very efficient)' + global_settings.web2py_crontype = 'soft' + elif cron and options.runcron: + logger.debug('Starting hardcron...') + global_settings.web2py_crontype = 'hard' + newcron.hardcron(options.folder).start() + # ## if no password provided and havetk start Tk interface # ## or start interface if we want to put in taskbar (system tray) diff --git a/gluon/winservice.py b/gluon/winservice.py index 38efe812..36d4f0a7 100644 --- a/gluon/winservice.py +++ b/gluon/winservice.py @@ -28,6 +28,7 @@ import servicemanager import _winreg from fileutils import up + __all__ = ['web2py_windows_service_handler'] @@ -152,20 +153,60 @@ class Web2pyService(Service): time.sleep(1) -def web2py_windows_service_handler(argv=None, opt_file='options'): +class Web2pyCronService(Web2pyService): + + _svc_name_ = 'web2py_cron' + _svc_display_name_ = 'web2py Cron Service' + _exe_args_ = 'options' + + def start(self): + import newcron + import global_settings + self.log('web2py server starting') + if not self.chdir(): + return + if len(sys.argv) == 2: + opt_mod = sys.argv[1] + else: + opt_mod = self._exe_args_ + options = __import__(opt_mod, [], [], '') + global_settings.global_settings.web2py_crontype = 'external' + if options.scheduler: # -K + apps = [app.strip() for app in options.scheduler.split( + ',') if check_existent_app(options, app.strip())] + else: + apps = None + self.extcron = newcron.extcron(options.folder, apps=apps) + try: + self.extcron.start() + except: + # self.server.stop() + self.extcron = None + raise + + def stop(self): + self.log('web2py cron stopping') + if not self.chdir(): + return + if self.extcron: + self.extcron.join() + +def register_service_handler( + name=Web2pyService, argv=None, opt_file='options'): path = os.path.dirname(__file__) web2py_path = up(path) if web2py_path.endswith('.zip'): # in case bianry distro 'library.zip' web2py_path = os.path.dirname(web2py_path) os.chdir(web2py_path) classstring = os.path.normpath( - os.path.join(web2py_path, 'gluon.winservice.Web2pyService')) + os.path.join(web2py_path, 'gluon.winservice.'+name.__name__)) if opt_file: - Web2pyService._exe_args_ = opt_file - win32serviceutil.HandleCommandLine(Web2pyService, - serviceClassString=classstring, argv=['', 'install']) - win32serviceutil.HandleCommandLine(Web2pyService, - serviceClassString=classstring, argv=argv) + name._exe_args_ = opt_file + win32serviceutil.HandleCommandLine( + name, serviceClassString=classstring, argv=['', 'install']) + win32serviceutil.HandleCommandLine( + name, serviceClassString=classstring, argv=argv) if __name__ == '__main__': - web2py_windows_service_handler() + register_service_handler(Web2pyService) + register_service_handler(Web2pyCronService)