Skip to content

Commit

Permalink
work
Browse files Browse the repository at this point in the history
  • Loading branch information
mcantelon committed May 1, 2024
1 parent 7dc005a commit 602ef48
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
7 changes: 5 additions & 2 deletions AIPscan/Aggregator/task_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""Collects a number of reusable components of tasks.py. Also ensures
the module remains clean and easy to refactor over time.
"""
import inspect
import json
import os
from datetime import datetime
Expand Down Expand Up @@ -162,10 +163,12 @@ 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, err):
calling_function_name = inspect.currentframe().f_back.f_code.co_name

fetch_error = FetchJobError()
fetch_error.fetch_job_id = fetch_job_id
fetch_error.message = message
fetch_error.message = f"{calling_function_name}: {err}"

db.session.add(fetch_error)
db.session.commit()
10 changes: 5 additions & 5 deletions AIPscan/Aggregator/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ 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, err)

return

Expand All @@ -87,7 +87,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, err)

return

Expand Down Expand Up @@ -188,10 +188,10 @@ 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_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 @@ -382,7 +382,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, e)

return

Expand Down
4 changes: 3 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,13 @@ 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_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_store_fetch_job_error_info: Test exception"
4 changes: 2 additions & 2 deletions AIPscan/Aggregator/tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ 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 == "get_mets: Non-200 HTTP code from METS download"
assert fetch_job_error.fetch_job_id == fetch_job.id


Expand Down Expand Up @@ -512,5 +512,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 == "workflow_coordinator: Task error"
assert fetch_job_error.fetch_job_id == fetch_job.id

0 comments on commit 602ef48

Please sign in to comment.