From 08d33c6f3493d8a3e09704e9d509a650b603b3c9 Mon Sep 17 00:00:00 2001 From: Oliver Newland Date: Mon, 9 Sep 2024 16:04:18 -0700 Subject: [PATCH] add sample job manifest file, API for read-only view of it --- snuba/admin/views.py | 7 +++++++ snuba/manual_jobs/manifest_reader.py | 17 +++++++++++++++++ snuba/manual_jobs/run_manifest.json | 1 + 3 files changed, 25 insertions(+) create mode 100644 snuba/manual_jobs/manifest_reader.py create mode 100644 snuba/manual_jobs/run_manifest.json diff --git a/snuba/admin/views.py b/snuba/admin/views.py index 0fd59285c9..91136e1646 100644 --- a/snuba/admin/views.py +++ b/snuba/admin/views.py @@ -72,6 +72,7 @@ get_writable_storage, ) from snuba.datasets.storages.storage_key import StorageKey +from snuba.manual_jobs.manifest_reader import read_jobs_manifest from snuba.migrations.connect import check_for_inactive_replicas from snuba.migrations.errors import InactiveClickhouseReplica, MigrationError from snuba.migrations.groups import MigrationGroup, get_group_readiness_state @@ -1264,3 +1265,9 @@ def delete() -> Response: @check_tool_perms(tools=[AdminTools.DELETE_TOOL]) def deletes_enabled() -> Response: return make_response(jsonify(deletes_are_enabled()), 200) + + +@application.route("/job-manifests", methods=["GET"]) +@check_tool_perms(tools=[AdminTools.ALL]) +def get_job_manifests() -> Response: + return make_response(jsonify(read_jobs_manifest()), 200) diff --git a/snuba/manual_jobs/manifest_reader.py b/snuba/manual_jobs/manifest_reader.py new file mode 100644 index 0000000000..43dd8b6368 --- /dev/null +++ b/snuba/manual_jobs/manifest_reader.py @@ -0,0 +1,17 @@ +import os +from typing import Any, Sequence + +import simplejson + + +class _ManifestReader: + def read(filename) -> Sequence[Any]: + local_root = os.path.dirname(__file__) + with open(os.path.join(local_root, filename)) as stream: + contents = simplejson.loads(stream.read()) + assert isinstance(contents, Sequence) + return contents + + +def read_jobs_manifest() -> Sequence[Any]: + return _ManifestReader.read("run_manifest.json") diff --git a/snuba/manual_jobs/run_manifest.json b/snuba/manual_jobs/run_manifest.json new file mode 100644 index 0000000000..6424a38cc3 --- /dev/null +++ b/snuba/manual_jobs/run_manifest.json @@ -0,0 +1 @@ +[{ "id": "abc1234", "job_type": "ToyJob", "params": { "p1": "value1" } }]