Skip to content

Commit b17616e

Browse files
committed
Rework journal parse error handling
- 3 parse failures in one journal file will kill the import - JSON parse failures will progress to the next journal entry - Journal data import failures will retry the same journal entry (in case it's a database lock issue) - This should allow imports to complete in the case of '-nan(ind)' (invalid JSON data) issues and the like
1 parent 04134ab commit b17616e

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

src/ExploData/explo_data/journal_parse.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,16 @@ def parse_journal(self, journal: Path, event: Event) -> int:
8787
retry = 2
8888
while True:
8989
result = self.parse_entry(line)
90-
if not result:
90+
if result == 1:
9191
failures += 1
9292
if (failures >= 3 and retry == 0) or event.is_set():
9393
return 1
94-
elif result:
94+
elif result == 2:
95+
failures += 1
96+
if failures >= 3:
97+
return 1
98+
break
99+
elif result == 0:
95100
break
96101
retry -= 1
97102
sleep(.1)
@@ -107,7 +112,7 @@ def parse_journal(self, journal: Path, event: Event) -> int:
107112
self._session.expunge(journal)
108113
return 0
109114

110-
def parse_entry(self, line: bytes) -> bool:
115+
def parse_entry(self, line: bytes) -> int:
111116
"""
112117
Parse a single line of a journal file. Load as JSON and pass to the processor.
113118
@@ -120,10 +125,13 @@ def parse_entry(self, line: bytes) -> bool:
120125
try:
121126
entry: Mapping[str, Any] = json.loads(line)
122127
self.process_entry(entry)
128+
except json.JSONDecodeError as ex:
129+
logger.error(f'Journal JSON decode issue:\n{line!r}\n', exc_info=ex)
130+
return 2
123131
except Exception as ex:
124-
logger.error(f'Invalid journal entry:\n{line!r}\n', exc_info=ex)
125-
return False
126-
return True
132+
logger.error(f'Journal parse error:\n{line!r}\n', exc_info=ex)
133+
return 1
134+
return 0
127135

128136
def process_entry(self, entry: Mapping[str, Any]) -> None:
129137
"""

0 commit comments

Comments
 (0)