Skip to content

Commit

Permalink
tagging and lint
Browse files Browse the repository at this point in the history
  • Loading branch information
morsecodist committed Jun 24, 2024
1 parent 76dc1ca commit 9921516
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions lib/idseq_utils/idseq_utils/batch_run_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,24 +96,29 @@ def __init__(self, bucket: str, prefix: str, inputs: dict[str, str]):
self.prefix = prefix
self.inputs = inputs


def _key(self, batch_args: dict) -> str:
hash = hashlib.sha256()
cache_dict = { "inputs": self.inputs, "batch_args": batch_args }
cache_dict = {"inputs": self.inputs, "batch_args": batch_args}
hash.update(json.dumps(cache_dict, sort_keys=True).encode())
return os.path.join(self.prefix, hash.hexdigest())

def get(self, batch_args: dict) -> Optional[str]:
try:
_s3_client.get_object(Bucket=self.bucket, Key=self._key(batch_args))["Body"].read()
resp = _s3_client.get_object(Bucket=self.bucket, Key=self._key(batch_args))
resp["Body"].read().decode()
except ClientError as e:
if e.response["Error"]["Code"] == "NoSuchKey":
return None
else:
raise e

def put(self, batch_args: dict, job_id: str):
_s3_client.put_object(Bucket=self.bucket, Key=self._key(batch_args), Body=job_id.encode())
_s3_client.put_object(
Bucket=self.bucket,
Key=self._key(batch_args),
Body=job_id.encode(),
Tagging="AlignmentCoordination=True",
)


def _run_batch_job(
Expand Down Expand Up @@ -244,6 +249,7 @@ def _job_queue(provisioning_model: str):
Key=input_key,
Body=json.dumps(inputs).encode(),
ContentType="application/json",
Tagging="AlignmentCoordination=True",
)

environment = {
Expand Down

0 comments on commit 9921516

Please sign in to comment.