Skip to content

Commit

Permalink
implemented real s3 mode on worker
Browse files Browse the repository at this point in the history
Signed-off-by: Duncan Ragsdale <[email protected]>
  • Loading branch information
Thistleman committed Nov 27, 2023
1 parent 677ba4e commit 9ea3982
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
9 changes: 7 additions & 2 deletions workers/pvinsight-validation-runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import zipfile
import subprocess
import logging
import boto3

# Basic logging configuration
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
Expand All @@ -53,6 +54,8 @@ def is_local():

is_s3_emulation = is_local()

S3_BUCKET_NAME = "pv-validation-hub-bucket"

def pull_from_s3(s3_file_path):
if s3_file_path.startswith('/'):
s3_file_path = s3_file_path[1:]
Expand All @@ -71,7 +74,8 @@ def pull_from_s3(s3_file_path):
with open(target_file_path, "wb") as f:
f.write(r.content)
else:
raise NotImplementedError("real s3 mode not implemented")
s3 = boto3.client('s3')
s3.download_file(S3_BUCKET_NAME, s3_file_path, target_file_path)

return target_file_path

Expand All @@ -92,7 +96,8 @@ def push_to_s3(local_file_path, s3_file_path):
if r.status_code != 204:
print(f"error put file {s3_file_path} to s3, status code {r.status_code} {r.content}", file=sys.stderr)
else:
raise NotImplementedError("real s3 mode not implemented")
s3 = boto3.client('s3')
s3.upload_file(local_file_path, S3_BUCKET_NAME, s3_file_path)


def convert_compressed_file_path_to_directory(compressed_file_path):
Expand Down
17 changes: 14 additions & 3 deletions workers/submission_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def is_local():

is_s3_emulation = is_local()

S3_BUCKET_NAME = "pv-validation-hub-bucket"


SUBMITTING = "submitting"
Expand Down Expand Up @@ -55,7 +56,12 @@ def pull_from_s3(s3_file_path):
with open(target_file_path, "wb") as f:
f.write(r.content)
else:
raise NotImplementedError("real s3 mode not implemented")
s3 = boto3.client('s3')

try:
s3.download_file(S3_BUCKET_NAME, s3_file_path, target_file_path)
except:
return None

return target_file_path

Expand All @@ -76,9 +82,14 @@ def push_to_s3(local_file_path, s3_file_path):
if r.status_code != 204:
print(f"error put file {s3_file_path} to s3, status code {r.status_code} {r.content}", file=sys.stderr)
else:
raise NotImplementedError("real s3 mode not implemented")


s3 = boto3.client('s3')

try:
s3.upload_file(local_file_path, S3_BUCKET_NAME, s3_file_path)
except:
return None

def list_s3_bucket(s3_dir):
if s3_dir.startswith('/'):
s3_dir = s3_dir[1:]
Expand Down

0 comments on commit 9ea3982

Please sign in to comment.