-
-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Rachel Chen
authored and
Rachel Chen
committed
Sep 16, 2024
1 parent
935a29c
commit 06710da
Showing
6 changed files
with
78 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,15 @@ | ||
import json | ||
from typing import Any, MutableMapping, Tuple, cast | ||
from typing import cast | ||
|
||
from snuba.manual_jobs import Job | ||
from snuba.utils.serializable_exception import SerializableException | ||
|
||
|
||
class JsonManifestParsingException(SerializableException): | ||
pass | ||
from snuba.manual_jobs import Job, JobSpec | ||
|
||
|
||
class JobLoader: | ||
@staticmethod | ||
def parse_json_manifest( | ||
filepath: str, kwargs: MutableMapping[Any, Any] | ||
) -> Tuple[str, str]: | ||
try: | ||
with open(filepath, "r") as json_manifest_file: | ||
json_manifest = json.load(json_manifest_file) | ||
job_id = json_manifest["id"] | ||
job_type = json_manifest["job_type"] | ||
for k, v in json_manifest["params"].items(): | ||
kwargs[k] = v | ||
return job_type, job_id | ||
|
||
except KeyError: | ||
raise JsonManifestParsingException( | ||
"The JSON manifest file should contain the `id` field and the `job_type` field" | ||
) | ||
|
||
@staticmethod | ||
def get_job_instance( | ||
job_type: str, job_id: str, dry_run: bool, **kwargs: Any | ||
) -> "Job": | ||
job_type_class = Job.class_from_name(job_type) | ||
def get_job_instance(job_spec: JobSpec, dry_run: bool) -> "Job": | ||
job_type_class = Job.class_from_name(job_spec.job_type) | ||
if job_type_class is None: | ||
raise Exception( | ||
f"Job does not exist. Did you make a file {job_type}.py yet?" | ||
f"Job does not exist. Did you make a file {job_spec.job_type}.py yet?" | ||
) | ||
|
||
return cast("Job", job_type_class(job_id, dry_run=dry_run, **kwargs)) | ||
return cast("Job", job_type_class(job_spec, dry_run=dry_run)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,30 @@ | ||
import os | ||
from typing import Any, Sequence | ||
import typing | ||
from typing import Sequence | ||
|
||
import simplejson | ||
|
||
from snuba.manual_jobs import JobSpec | ||
|
||
|
||
class ManifestReader: | ||
@staticmethod | ||
def read(filename: str) -> Sequence[Any]: | ||
def read(filename: str) -> Sequence[JobSpec]: | ||
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 | ||
|
||
job_specs = [] | ||
for content in contents: | ||
content_dict = dict(zip(content[::2], content[1::2])) | ||
job_spec = JobSpec( | ||
job_id=typing.cast(str, content_dict.get("id")), | ||
job_type=typing.cast(str, content_dict.get("job_type")), | ||
params=content_dict.get("params"), | ||
) | ||
job_specs.append(job_spec) | ||
return job_specs | ||
|
||
|
||
def read_jobs_manifest() -> Sequence[Any]: | ||
def read_jobs_manifest() -> Sequence[JobSpec]: | ||
return ManifestReader.read("run_manifest.json") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters