|
2 | 2 | import logging |
3 | 3 | import os |
4 | 4 |
|
| 5 | +import requests |
5 | 6 | from cumulus_logger import CumulusLogger |
6 | 7 | from cumulus_process import Process |
7 | 8 | from harmony import LinkType |
|
12 | 13 | CUMULUS_LOGGER = CumulusLogger('get_harmony_job_status') |
13 | 14 |
|
14 | 15 |
|
| 16 | +class HarmonyTransientError(Exception): |
| 17 | + """Exception raised when the Harmony API returns a transient 5xx error""" |
| 18 | + |
| 19 | + def __init__(self, message): |
| 20 | + super().__init__(message) |
| 21 | + |
| 22 | + |
15 | 23 | class HarmonyJobIncompleteError(Exception): |
16 | 24 | """Exception raised when a harmony job is not complete""" |
17 | 25 |
|
@@ -98,12 +106,26 @@ def check_harmony_job( |
98 | 106 | """ |
99 | 107 |
|
100 | 108 | harmony_client = utils.get_harmony_client(cmr_env) |
101 | | - job_status = harmony_client.status(harmony_job_id) |
| 109 | + try: |
| 110 | + job_status = harmony_client.status(harmony_job_id) |
| 111 | + except requests.exceptions.HTTPError as exc: |
| 112 | + if exc.response is not None and exc.response.status_code >= 500: |
| 113 | + raise HarmonyTransientError( |
| 114 | + f'Harmony API returned a transient error checking status of job {harmony_job_id}: {exc}' |
| 115 | + ) from exc |
| 116 | + raise |
102 | 117 |
|
103 | 118 | # For a successful job, return the status; for all other states, raise an exception. |
104 | 119 | if job_status.get('status') == 'successful': |
105 | 120 | # Check that the harmony job returned data to confirm that the job was successful |
106 | | - result_urls = list(harmony_client.result_urls(harmony_job_id, link_type=LinkType.s3)) |
| 121 | + try: |
| 122 | + result_urls = list(harmony_client.result_urls(harmony_job_id, link_type=LinkType.s3)) |
| 123 | + except requests.exceptions.HTTPError as exc: |
| 124 | + if exc.response is not None and exc.response.status_code >= 500: |
| 125 | + raise HarmonyTransientError( |
| 126 | + f'Harmony API returned a transient error fetching result URLs for job {harmony_job_id}: {exc}' |
| 127 | + ) from exc |
| 128 | + raise |
107 | 129 | if not result_urls: |
108 | 130 | error_msg = ( |
109 | 131 | f'Harmony job {harmony_job_id} completed successfully but returned no data for {variable} and {crs}' |
|
0 commit comments