changeset 32148996668f in trytond:default
details: https://hg.tryton.org/trytond?cmd=changeset;node=32148996668f
description:
        Add option to run cron once

        issue9475
        review307931002
diffstat:

 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 deletions(-)

diffs (61 lines):

diff -r 798e9c54e622 -r 32148996668f CHANGELOG
--- a/CHANGELOG Sat Jul 25 07:59:07 2020 +0200
+++ b/CHANGELOG Sat Jul 25 08:03:02 2020 +0200
@@ -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 -r 798e9c54e622 -r 32148996668f bin/trytond-cron
--- a/bin/trytond-cron  Sat Jul 25 07:59:07 2020 +0200
+++ b/bin/trytond-cron  Sat Jul 25 08:03:02 2020 +0200
@@ -12,7 +12,7 @@
 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 -r 798e9c54e622 -r 32148996668f doc/topics/start_server.rst
--- a/doc/topics/start_server.rst       Sat Jul 25 07:59:07 2020 +0200
+++ b/doc/topics/start_server.rst       Sat Jul 25 08:03:02 2020 +0200
@@ -54,6 +54,8 @@
 
 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 -r 798e9c54e622 -r 32148996668f trytond/commandline.py
--- a/trytond/commandline.py    Sat Jul 25 07:59:07 2020 +0200
+++ b/trytond/commandline.py    Sat Jul 25 08:03:02 2020 +0200
@@ -60,6 +60,13 @@
     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 -r 798e9c54e622 -r 32148996668f trytond/cron.py
--- a/trytond/cron.py   Sat Jul 25 07:59:07 2020 +0200
+++ b/trytond/cron.py   Sat Jul 25 08:03:02 2020 +0200
@@ -35,4 +35,8 @@
             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()

Reply via email to