Skip to content

Commit 38e287e

Browse files
Cooper StimsonChristian Miller
Cooper Stimson
and
Christian Miller
committed
Patch FileTaskHandler._read to accommodate pre-migration timezone naive logs.
Co-authored-by: Cooper Stimson <cooper.stimson@cloverhealth.com> Co-authored-by: Christian Miller <christian.miller@cloverhealth.com>
1 parent a229126 commit 38e287e

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

airflow/utils/log/file_task_handler.py

+27-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def _read(self, ti, try_number, metadata=None):
121121
except (AirflowConfigException, ValueError):
122122
pass
123123

124-
response = requests.get(url, timeout=timeout)
124+
response, log = self._try_both_log_locations(url, timeout, log)
125125

126126
# Check if the resource was properly fetched
127127
response.raise_for_status()
@@ -205,3 +205,29 @@ def _init_file(self, ti):
205205
os.chmod(full_path, 0o666)
206206

207207
return full_path
208+
209+
def _try_both_log_locations(self, url, timeout, log):
210+
"""If a logfile cannot be found, try the timezone naive url format."""
211+
response = requests.get(url, timeout=timeout)
212+
213+
try:
214+
response.raise_for_status()
215+
except requests.HTTPError as _:
216+
log += "*** (clover patch) Cannot find log at filename {url}\n".format(url=url)
217+
old_url = self._convert_to_old_url(url)
218+
try:
219+
response = requests.get(old_url, timeout=timeout)
220+
response.raise_for_status()
221+
except requests.HTTPError as _:
222+
log += "*** (clover patch) Cannot find log at filename {old_url}\n".format(old_url=old_url)
223+
224+
return response, log
225+
226+
@staticmethod
227+
def _convert_to_old_url(url):
228+
"""Convert a logfile url from timezone aware to timezone naive.
229+
230+
..NOTE ::
231+
This assumes that all timestamps involved are UTC.
232+
"""
233+
return url.replace('+00:00', '')

0 commit comments

Comments
 (0)