--force_migrate and --cron_threads, thanks Paolo Pastori
This commit is contained in:
+27
-6
@@ -23,9 +23,15 @@ for the benefit of code maintainers/developers:
|
|||||||
'--run_system_tests')
|
'--run_system_tests')
|
||||||
- remember to allow the '-' too as word separator (e.g.
|
- remember to allow the '-' too as word separator (e.g.
|
||||||
'--run-system-tests') but do not use this form on help
|
'--run-system-tests') but do not use this form on help
|
||||||
|
(add the minus version of the option to _omitted_opts
|
||||||
|
to hide it in usage help)
|
||||||
- prefer short names on help messages, instead use
|
- prefer short names on help messages, instead use
|
||||||
all options names in warning/error messages (e.g.
|
all options names in warning/error messages (e.g.
|
||||||
'-R/--run requires -S/--shell')
|
'-R/--run requires -S/--shell')
|
||||||
|
|
||||||
|
Notice that options must be included into opt_map dictionary
|
||||||
|
(defined in parse_args function) to be available in
|
||||||
|
configuration file.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
@@ -90,11 +96,12 @@ def console(version):
|
|||||||
# most of the options but do not show both versions on help
|
# most of the options but do not show both versions on help
|
||||||
_omitted_opts = ('--add-options', '--errors-to-console',
|
_omitted_opts = ('--add-options', '--errors-to-console',
|
||||||
'--no-banner', '--log-level', '--no-gui', '--import-models',
|
'--no-banner', '--log-level', '--no-gui', '--import-models',
|
||||||
|
'--force-migrate',
|
||||||
'--server-name', '--server-key', '--server-cert', '--ca-cert',
|
'--server-name', '--server-key', '--server-cert', '--ca-cert',
|
||||||
'--pid-filename', '--log-filename', '--min-threads',
|
'--pid-filename', '--log-filename', '--min-threads',
|
||||||
'--max-threads', '--request-queue-size', '--socket-timeout',
|
'--max-threads', '--request-queue-size', '--socket-timeout',
|
||||||
'--profiler-dir', '--with-scheduler', '--with-cron',
|
'--profiler-dir', '--with-scheduler', '--with-cron',
|
||||||
'--soft-cron', '--cron-run',
|
'--cron-threads', '--soft-cron', '--cron-run',
|
||||||
'--run-doctests', '--run-system-tests', '--with-coverage')
|
'--run-doctests', '--run-system-tests', '--with-coverage')
|
||||||
|
|
||||||
_hidden_options = _omitted_opts + tuple(deprecated_opts.keys())
|
_hidden_options = _omitted_opts + tuple(deprecated_opts.keys())
|
||||||
@@ -259,12 +266,11 @@ web2py will attempt to run a GUI to ask for it when starting the web server
|
|||||||
'(default is %(default)s), see -S above. NOTE: when the APP_ENV '
|
'(default is %(default)s), see -S above. NOTE: when the APP_ENV '
|
||||||
'argument of -S include a controller c automatic import of '
|
'argument of -S include a controller c automatic import of '
|
||||||
'models is always enabled')
|
'models is always enabled')
|
||||||
g.add_argument('--force_migrate',
|
g.add_argument('--force_migrate', '--force-migrate',
|
||||||
default=False,
|
default=False,
|
||||||
action='store_true',
|
action='store_true', help=
|
||||||
help=
|
'force DAL to migrate all tables that should be migrated when enabled; '
|
||||||
'force DAL to migrate all tables that should be migrated when enabled; '
|
'monkeypatch in the DAL class to force _migrate_enabled=True')
|
||||||
'monkeypatch in the DAL class to force _migrate_enabled=True')
|
|
||||||
g.add_argument('-R', '--run',
|
g.add_argument('-R', '--run',
|
||||||
type=existing_file,
|
type=existing_file,
|
||||||
metavar='PYTHON_FILE', help=
|
metavar='PYTHON_FILE', help=
|
||||||
@@ -452,6 +458,19 @@ web2py will attempt to run a GUI to ask for it when starting the web server
|
|||||||
'only, the default behaviour is to read the crontab for all of the '
|
'only, the default behaviour is to read the crontab for all of the '
|
||||||
'installed applications. NOTE: this option can be used multiple '
|
'installed applications. NOTE: this option can be used multiple '
|
||||||
'times to build the list of crontabs to be processed by cron')
|
'times to build the list of crontabs to be processed by cron')
|
||||||
|
def positive_int(v, err_label='value'):
|
||||||
|
try:
|
||||||
|
iv = int(v)
|
||||||
|
if iv <= 0: raise ValueError()
|
||||||
|
return iv
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
|
raise argparse.ArgumentTypeError("bad %s %s" % (err_label, v))
|
||||||
|
def cron_threads(v):
|
||||||
|
return positive_int(v, err_label='cron_threads')
|
||||||
|
g.add_argument('--cron_threads', '--cron-threads',
|
||||||
|
type=cron_threads, metavar='NUM',
|
||||||
|
help='maximum number of cron threads (5)')
|
||||||
g.add_argument('--soft_cron', '--soft-cron',
|
g.add_argument('--soft_cron', '--soft-cron',
|
||||||
'--softcron', # deprecated
|
'--softcron', # deprecated
|
||||||
default=False,
|
default=False,
|
||||||
@@ -664,6 +683,7 @@ def parse_args(parser, cli_args, deprecated_opts, integer_log_level,
|
|||||||
'bpython': store_true,
|
'bpython': store_true,
|
||||||
'plain': store_true,
|
'plain': store_true,
|
||||||
'import_models': store_true,
|
'import_models': store_true,
|
||||||
|
'force_migrate': store_true,
|
||||||
'run': str_or_default,
|
'run': str_or_default,
|
||||||
'args': list_or_default,
|
'args': list_or_default,
|
||||||
# web server options
|
# web server options
|
||||||
@@ -688,6 +708,7 @@ def parse_args(parser, cli_args, deprecated_opts, integer_log_level,
|
|||||||
# cron options
|
# cron options
|
||||||
'with_cron': store_true,
|
'with_cron': store_true,
|
||||||
'crontab': list_or_default,
|
'crontab': list_or_default,
|
||||||
|
'cron_threads': str_or_default,
|
||||||
'soft_cron': store_true,
|
'soft_cron': store_true,
|
||||||
'cron_run': store_true,
|
'cron_run': store_true,
|
||||||
# test options
|
# test options
|
||||||
|
|||||||
+7
-1
@@ -334,7 +334,7 @@ class SimplePool(object):
|
|||||||
self.running = set()
|
self.running = set()
|
||||||
|
|
||||||
def grow(self, size):
|
def grow(self, size):
|
||||||
if size > self.size:
|
if size and size > self.size:
|
||||||
self.size = size
|
self.size = size
|
||||||
|
|
||||||
def start(self, t):
|
def start(self, t):
|
||||||
@@ -380,8 +380,14 @@ class SimplePool(object):
|
|||||||
|
|
||||||
_dancer = SimplePool(5, worker_cls=SoftWorker)
|
_dancer = SimplePool(5, worker_cls=SoftWorker)
|
||||||
|
|
||||||
|
def dancer_size(size):
|
||||||
|
_dancer.grow(size)
|
||||||
|
|
||||||
_launcher = SimplePool(5)
|
_launcher = SimplePool(5)
|
||||||
|
|
||||||
|
def launcher_size(size):
|
||||||
|
_launcher.grow(size)
|
||||||
|
|
||||||
def crondance(applications_parent, ctype='hard', startup=False, apps=None):
|
def crondance(applications_parent, ctype='hard', startup=False, apps=None):
|
||||||
"""
|
"""
|
||||||
Does the periodic job of cron service: read the crontab(s) and launch
|
Does the periodic job of cron service: read the crontab(s) and launch
|
||||||
|
|||||||
@@ -744,6 +744,10 @@ def start():
|
|||||||
cron_job=options.cron_job, force_migrate=options.force_migrate)
|
cron_job=options.cron_job, force_migrate=options.force_migrate)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# set size of cron thread pools
|
||||||
|
newcron.dancer_size(options.min_threads)
|
||||||
|
newcron.launcher_size(options.cron_threads)
|
||||||
|
|
||||||
if options.cron_run:
|
if options.cron_run:
|
||||||
# run cron (extcron) and exit
|
# run cron (extcron) and exit
|
||||||
logger.debug('Running extcron...')
|
logger.debug('Running extcron...')
|
||||||
|
|||||||
Reference in New Issue
Block a user