From 9202f337e33ba57bda88e62badec4dbb655ff60e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sat, 25 Jul 2020 08:03:02 +0200 Subject: [PATCH] Add option to run cron once issue9475 review307931002 --- CHANGELOG | 1 + bin/trytond-cron | 2 +- doc/topics/start_server.rst | 2 ++ trytond/commandline.py | 7 +++++++ trytond/cron.py | 4 ++++ 5 files changed, 15 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 7e4a3b13c2..ba10a343a5 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,4 @@ +* Add option to run cron once * Add defaults option to route * Add escape_wildcard in tools * Add option to ensure emails are sent diff --git a/bin/trytond-cron b/bin/trytond-cron index 683424154f..fd58fe85a3 100755 --- a/bin/trytond-cron +++ b/bin/trytond-cron @@ -12,7 +12,7 @@ if os.path.isdir(DIR): import trytond.commandline as commandline from trytond.config import config -parser = commandline.get_parser_daemon() +parser = commandline.get_parser_cron() options = parser.parse_args() config.update_etc(options.configfile) commandline.config_log(options) diff --git a/doc/topics/start_server.rst b/doc/topics/start_server.rst index e653a87d60..43f78f4629 100644 --- a/doc/topics/start_server.rst +++ b/doc/topics/start_server.rst @@ -54,6 +54,8 @@ run the cron server with this command line:: The server will wake up every minutes and preform the scheduled actions defined in the `database`. +You can also launch the command every few minutes from a scheduler with the +option `--once`. Worker service ============== diff --git a/trytond/commandline.py b/trytond/commandline.py index 2847253012..71e3dc1a1f 100644 --- a/trytond/commandline.py +++ b/trytond/commandline.py @@ -60,6 +60,13 @@ def get_parser_worker(): return parser +def get_parser_cron(): + parser = get_parser_daemon() + parser.add_argument("-1", "--once", dest='once', action='store_true', + help="run pending tasks and halt") + return parser + + def get_parser_admin(): parser = get_parser() diff --git a/trytond/cron.py b/trytond/cron.py index 1713bf8e89..e7e37f496e 100644 --- a/trytond/cron.py +++ b/trytond/cron.py @@ -35,4 +35,8 @@ def run(options): logger.info('start thread for "%s"', db_name) thread.start() threads[db_name] = thread + if options.once: + break time.sleep(60) + for thread in threads.values(): + thread.join()