From 7092e4e4acfcffd82d2f8de36d96099352309cd0 Mon Sep 17 00:00:00 2001
From: Antoine Lambert <anlambert@softwareheritage.org>
Date: Thu, 22 Jun 2023 14:36:13 +0200
Subject: [PATCH] cli: Use temporary scheduler as fallback when no
 configuration detected

In order to simplify the testing of listers, allow to call the run command
of swh-lister CLI without scheduler configuration. In that case a temporary
scheduler instance with a postgresql backend is created and used.

It enables to easily test a lister with the following command:

$ swh -l DEBUG lister run <lister_name> url=<forge_url>
---
 requirements-swh.txt | 2 +-
 swh/lister/cli.py    | 8 ++++++++
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/requirements-swh.txt b/requirements-swh.txt
index 6bf26fec..94356027 100644
--- a/requirements-swh.txt
+++ b/requirements-swh.txt
@@ -1,2 +1,2 @@
 swh.core[db,github] >= 2.22.0
-swh.scheduler >= 0.8
+swh.scheduler >= 1.12.0
diff --git a/swh/lister/cli.py b/swh/lister/cli.py
index 028e2514..db24789d 100644
--- a/swh/lister/cli.py
+++ b/swh/lister/cli.py
@@ -69,6 +69,14 @@ def run(ctx, lister, options):
     if options:
         config.update(parse_options(options)[1])
 
+    if "scheduler" not in config:
+        logger.warning(
+            "No scheduler configuration detected, using a temporary instance "
+            "with postgresql backend instead."
+        )
+
+        config["scheduler"] = {"cls": "temporary"}
+
     get_lister(lister, **config).run()
 
 
-- 
GitLab