From d8953568b2ef35c627c71db6897b9db32421b498 Mon Sep 17 00:00:00 2001 From: Mike Lang Date: Sat, 31 Aug 2024 02:39:26 +1000 Subject: [PATCH] playlist_manager: Add --once option --- playlist_manager/playlist_manager/main.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/playlist_manager/playlist_manager/main.py b/playlist_manager/playlist_manager/main.py index 5ceb108..09ccb65 100644 --- a/playlist_manager/playlist_manager/main.py +++ b/playlist_manager/playlist_manager/main.py @@ -437,6 +437,7 @@ def main( playlists, upload_location_allowlist="youtube", interval=600, + once=False, metrics_port=8007, backdoor_port=0, ): @@ -452,6 +453,7 @@ def main( upload_location. interval is how often to check for new videos, default every 10min. + If --once is given, interval is ignored and we exit after one check. """ common.PromLogCountsHandler.install() common.install_stacksampler() @@ -475,12 +477,15 @@ def main( dbmanager = DBManager(dsn=dbconnect) manager = PlaylistManager(dbmanager, client, upload_locations, playlists) - while not stop.is_set(): - try: - manager.run_once() - except Exception: - logging.exception("Failed to run playlist manager") - manager.reset() - stop.wait(interval) # wait for interval, or until stopping + if once: + manager.run_once() + else: + while not stop.is_set(): + try: + manager.run_once() + except Exception: + logging.exception("Failed to run playlist manager") + manager.reset() + stop.wait(interval) # wait for interval, or until stopping logging.info("Stopped")