Skip to content

Commit

Permalink
Merge pull request #2 from b97pla/feature/use_optional_path_parameter
Browse files Browse the repository at this point in the history
if specified, use a supplied path to the pdc archive
  • Loading branch information
johandahlberg authored Jun 5, 2018
2 parents 61672b0 + 4edd114 commit 0b5732d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
__pycache__
*.swp
*.swo
.idea/
8 changes: 5 additions & 3 deletions archive_verify/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ async def verify(request):
host = body["host"]
archive = body["archive"]
description = body["description"]

path = body.get("path")

src_root = request.app["config"]["pdc_root_dir"].format(host)
archive_path = os.path.join(src_root, archive)
# use a supplied path if available, otherwise construct it from the src_root and archive
archive_path = path or os.path.join(src_root, archive)

redis_conn = Redis()
q = Queue(connection=redis_conn)
Expand All @@ -38,7 +40,7 @@ async def verify(request):
# config e.g. setups the queue to keep the job results indefinately,
# therefore they we will have to remove them ourselves afterwards.
job = q.enqueue_call(verify_archive,
args=(archive, host, description, request.app["config"]),
args=(archive, archive_path, description, request.app["config"]),
timeout=request.app["config"]["job_timeout"],
result_ttl=request.app["config"]["job_result_ttl"],
ttl=request.app["config"]["job_ttl"])
Expand Down
8 changes: 3 additions & 5 deletions archive_verify/workers.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,26 +90,24 @@ def compare_md5sum(archive_dir):
else:
return True

def verify_archive(archive, host, description, config):
def verify_archive(archive, archive_path, description, config):
"""
Our main worker function. This will be put into the RQ/Redis queue when the /verify endpoint gets called.
Downloads the specified archive from PDC and then verifies the MD5 sums.
:param archive: The name of the archive we shall download
:param host: The host the archive was previsouly uploaded from
:param archive_path: The path to the archive on PDC
:param description: The unique description that was used when uploading the archive to PDC
:param config: A dict containing the apps configuration
:returns A JSON with the result that will be kept in the Redis queue
"""
dest_root = config["verify_root_dir"]
dsmc_log_dir = config["dsmc_log_dir"]
whitelist = config["whitelisted_warnings"]
src_root = config["pdc_root_dir"].format(host)
src = os.path.join(src_root, archive)
job_id = rq.get_current_job().id
dest = "{}_{}".format(os.path.join(dest_root, archive), job_id)

download_ok = download_from_pdc(src, description, dest, dsmc_log_dir, whitelist)
download_ok = download_from_pdc(archive_path, description, dest, dsmc_log_dir, whitelist)

if not download_ok:
return {"state": "error", "msg": "failed to properly download archive from pdc", "path": dest}
Expand Down

0 comments on commit 0b5732d

Please sign in to comment.