new widget.py thanks Niphlod
This commit is contained in:
@@ -1 +1 @@
|
|||||||
Version 2.00.0 (2012-08-24 17:05:15) dev
|
Version 2.00.0 (2012-08-24 17:32:21) dev
|
||||||
|
|||||||
+30
-9
@@ -754,9 +754,11 @@ def console():
|
|||||||
default='',
|
default='',
|
||||||
help=msg)
|
help=msg)
|
||||||
|
|
||||||
msg = 'run scheduled tasks for the specified apps'
|
msg = 'run scheduled tasks for the specified apps: expects a list of '
|
||||||
msg += '-K app1,app2,app3'
|
msg += 'app names as -K app1,app2,app3 '
|
||||||
msg += 'requires a scheduler defined in the models'
|
msg += 'or a list of app:groups as -K app1:group1:group2,app2:group1 '
|
||||||
|
msg += 'to override specific group_names. (only strings, no spaces '
|
||||||
|
msg += 'allowed. Requires a scheduler defined in the models'
|
||||||
parser.add_option('-K',
|
parser.add_option('-K',
|
||||||
'--scheduler',
|
'--scheduler',
|
||||||
dest='scheduler',
|
dest='scheduler',
|
||||||
@@ -917,6 +919,17 @@ def console():
|
|||||||
options.interfaces = [
|
options.interfaces = [
|
||||||
tuple(interface) for interface in options.interfaces]
|
tuple(interface) for interface in options.interfaces]
|
||||||
|
|
||||||
|
# accepts --scheduler in the form
|
||||||
|
# "app:group1,group2,app2:group1"
|
||||||
|
scheduler = []
|
||||||
|
options.scheduler_groups = None
|
||||||
|
if isinstance(options.scheduler, str):
|
||||||
|
if ':' in options.scheduler:
|
||||||
|
for opt in options.scheduler.split(','):
|
||||||
|
scheduler.append(opt.split(':'))
|
||||||
|
options.scheduler = ','.join([app[0] for app in scheduler])
|
||||||
|
options.scheduler_groups = scheduler
|
||||||
|
|
||||||
if options.numthreads is not None and options.minthreads is None:
|
if options.numthreads is not None and options.minthreads is None:
|
||||||
options.minthreads = options.numthreads # legacy
|
options.minthreads = options.numthreads # legacy
|
||||||
|
|
||||||
@@ -940,20 +953,28 @@ def check_existent_app(options,appname):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
def start_schedulers(options):
|
def start_schedulers(options):
|
||||||
apps = [app.strip() for app in options.scheduler.split(',')]
|
|
||||||
try:
|
try:
|
||||||
from multiprocessing import Process
|
from multiprocessing import Process
|
||||||
except:
|
except:
|
||||||
sys.stderr.write('Sorry, -K only supported for python 2.6-2.7\n')
|
sys.stderr.write('Sorry, -K only supported for python 2.6-2.7\n')
|
||||||
return
|
return
|
||||||
processes = []
|
processes = []
|
||||||
code = "from gluon import current;current._scheduler.loop()"
|
apps = [(app.strip(), None) for app in options.scheduler.split(',')]
|
||||||
|
if options.scheduler_groups:
|
||||||
|
apps = options.scheduler_groups
|
||||||
for app in apps:
|
for app in apps:
|
||||||
if not check_existent_app(options, app):
|
if len(app) == 1 or app[1] == None:
|
||||||
print "Application '%s' doesn't exist, skipping" % (app)
|
code = "from gluon import current;current._scheduler.loop()"
|
||||||
|
else:
|
||||||
|
code = "from gluon import current;current._scheduler.group_names = ['%s'];"
|
||||||
|
code += "current._scheduler.loop()"
|
||||||
|
code = code % ("','".join(app[1:]))
|
||||||
|
app_ = app[0]
|
||||||
|
if not check_existent_app(options, app_):
|
||||||
|
print "Application '%s' doesn't exist, skipping" % (app_)
|
||||||
continue
|
continue
|
||||||
print 'starting scheduler for "%s"...' % app
|
print 'starting scheduler for "%s"...' % app_
|
||||||
args = (app,True,True,None,False,code)
|
args = (app_,True,True,None,False,code)
|
||||||
logging.getLogger().setLevel(options.debuglevel)
|
logging.getLogger().setLevel(options.debuglevel)
|
||||||
p = Process(target=run, args=args)
|
p = Process(target=run, args=args)
|
||||||
processes.append(p)
|
processes.append(p)
|
||||||
|
|||||||
Reference in New Issue
Block a user