Skip to content

Commit

Permalink
work
Browse files Browse the repository at this point in the history
  • Loading branch information
mcantelon committed Mar 27, 2024
1 parent a012822 commit 914a168
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
4 changes: 2 additions & 2 deletions AIPscan/Aggregator/task_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,10 @@ def write_mets(http_response, package_uuid, subdir):
return download_file


def store_fetch_job_error_infomation(fetch_job_id, message):
def store_fetch_job_error_infomation(fetch_job_id, location, err):
fetch_error = FetchJobError()
fetch_error.fetch_job_id = fetch_job_id
fetch_error.message = message
fetch_error.message = f"{location}: {err}"

db.session.add(fetch_error)
db.session.commit()
14 changes: 9 additions & 5 deletions AIPscan/Aggregator/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ def start_mets_task(
current_location, storage_service
)
except Exception as err:
store_fetch_job_error_infomation(fetch_job_id, str(err))
store_fetch_job_error_infomation(
fetch_job_id, "create_or_update_storage_location", err
)

return

Expand All @@ -79,7 +81,7 @@ def start_mets_task(
origin_pipeline, storage_service
)
except Exception as err:
store_fetch_job_error_infomation(fetch_job_id, str(err))
store_fetch_job_error_infomation(fetch_job_id, "create_or_update_pipeline", err)

return

Expand Down Expand Up @@ -180,10 +182,12 @@ def workflow_coordinator(
break

if isinstance(package_lists_task.info, TaskError):
store_fetch_job_error_infomation(fetch_job_id, str(package_lists_task.info))
store_fetch_job_error_infomation(
fetch_job_id, "package_lists_request", package_lists_task.info
)

# Re-raise.
raise (package_lists_task.info)
raise package_lists_task.info

total_package_lists = package_lists_task.info["totalPackageLists"]

Expand Down Expand Up @@ -341,7 +345,7 @@ def get_mets(
package_list_no,
)
except Exception as e:
store_fetch_job_error_infomation(fetch_job_id, str(e))
store_fetch_job_error_infomation(fetch_job_id, "download_mets", e)

return

Expand Down
6 changes: 5 additions & 1 deletion AIPscan/Aggregator/tests/test_task_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,11 +319,15 @@ def test_store_fetch_job_error_info(app_instance):
assert fetch_job_error is None

# Attempt to store fetch job error and make sure it ends up in the database
task_helpers.store_fetch_job_error_infomation(fetch_job.id, "Test")
test_exception = Exception("Test exception")
task_helpers.store_fetch_job_error_infomation(
fetch_job.id, "Test location", test_exception
)

fetch_job_error = models.FetchJobError.query.filter_by(
fetch_job_id=fetch_job.id
).first()

assert fetch_job_error is not None
assert fetch_job_error.fetch_job_id == fetch_job.id
assert fetch_job_error.message == "Test location: Test exception"
6 changes: 4 additions & 2 deletions AIPscan/Aggregator/tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,9 @@ def test_store_fetch_job_error_during_get_mets(app_instance, tmpdir):
fetch_job_error = FetchJobError.query.filter_by(fetch_job_id=fetch_job.id).first()

assert fetch_job_error is not None
assert fetch_job_error.message == "Non-200 HTTP code from METS download"
assert (
fetch_job_error.message == "download_mets: Non-200 HTTP code from METS download"
)
assert fetch_job_error.fetch_job_id == fetch_job.id


Expand Down Expand Up @@ -446,5 +448,5 @@ class MockPackageListsRequestAsyncResult:
fetch_job_error = FetchJobError.query.filter_by(fetch_job_id=fetch_job.id).first()

assert fetch_job_error is not None
assert fetch_job_error.message == "Task error"
assert fetch_job_error.message == "package_lists_request: Task error"
assert fetch_job_error.fetch_job_id == fetch_job.id

0 comments on commit 914a168

Please sign in to comment.