Repository: mozilla/bugbug

Issue:
Return a list of known tasks together with the selection results
This way, when a new task is added, the scheduler in mozilla-central can schedule it.


Discussion:

Resolving patch:
diff --git a/http_service/bugbug_http/boot.py b/http_service/bugbug_http/boot.py
--- a/http_service/bugbug_http/boot.py
+++ b/http_service/bugbug_http/boot.py
@@ -7,6 +7,8 @@
 import logging
 import os
 
+import requests
+
 from bugbug import repository, test_scheduling, utils
 from bugbug_http import ALLOW_MISSING_MODELS, REPO_DIR
 
@@ -87,9 +89,20 @@ def extract_commit_experiences():
             )
             assert ALLOW_MISSING_MODELS
 
+    def retrieve_schedulable_tasks():
+        # Store in a file the list of tasks in the latest autoland push.
+        r = requests.get(
+            "https://firefox-ci-tc.services.mozilla.com/api/index/v1/task/gecko.v2.autoland.latest.taskgraph.decision/artifacts/public/target-tasks.json"
+        )
+        r.raise_for_status()
+        with open("known_tasks", "w") as f:
+            f.write("\n".join(r.json()))
+
     with concurrent.futures.ThreadPoolExecutor() as executor:
         clone_autoland_future = executor.submit(clone_autoland)
 
+        retrieve_schedulable_tasks_future = executor.submit(retrieve_schedulable_tasks)
+
         commits_db_extracted = extract_commits()
         extract_commit_experiences()
         extract_touched_together()
@@ -129,4 +142,7 @@ def extract_commit_experiences():
                     pass
             logger.info("Touched together DB updated.")
 
+        # Wait list of schedulable tasks to be downloaded and written to disk.
+        retrieve_schedulable_tasks_future.result()
+
     logger.info("Worker boot done")
diff --git a/http_service/bugbug_http/models.py b/http_service/bugbug_http/models.py
--- a/http_service/bugbug_http/models.py
+++ b/http_service/bugbug_http/models.py
@@ -6,6 +6,8 @@
 import logging
 import os
 from datetime import timedelta
+from functools import lru_cache
+from typing import Tuple
 
 import orjson
 import requests
@@ -103,6 +105,12 @@ def classify_bug(model_name, bug_ids, bugzilla_token):
     return "OK"
 
 
+@lru_cache(maxsize=None)
+def get_known_tasks() -> Tuple[str, ...]:
+    with open("known_tasks", "r") as f:
+        return tuple(l.strip() for l in f)
+
+
 def schedule_tests(branch, rev):
     from bugbug_http.app import JobInfo
     from bugbug_http import REPO_DIR
@@ -159,6 +167,7 @@ def schedule_tests(branch, rev):
         "groups": groups,
         "reduced_tasks": {t: c for t, c in tasks.items() if t in reduced},
         "reduced_tasks_higher": {t: c for t, c in tasks.items() if t in reduced_higher},
+        "known_tasks": get_known_tasks(),
     }
     setkey(job.result_key, orjson.dumps(data))
 


Test patch:
diff --git a/http_service/tests/conftest.py b/http_service/tests/conftest.py
--- a/http_service/tests/conftest.py
+++ b/http_service/tests/conftest.py
@@ -271,6 +271,9 @@ def mock_component_taskcluster_artifact():
 
 @pytest.fixture
 def mock_schedule_tests_classify(monkeypatch):
+    with open("known_tasks", "w") as f:
+        f.write("prova")
+
     # Initialize a mock past failures DB.
     for granularity in ("label", "group"):
         past_failures_data = test_scheduling.get_past_failures(granularity)
diff --git a/http_service/tests/test_schedule_tests.py b/http_service/tests/test_schedule_tests.py
--- a/http_service/tests/test_schedule_tests.py
+++ b/http_service/tests/test_schedule_tests.py
@@ -82,4 +82,5 @@ def test_simple_schedule(
         "groups": groups_to_choose,
         "reduced_tasks": reduced_labels,
         "reduced_tasks_higher": reduced_labels,
+        "known_tasks": ["prova"],
     }