mirror of
https://github.com/jlengrand/bugsink.git
synced 2026-03-10 08:01:17 +00:00
minidump after-digest cleanup
envelope-based happy path only
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import contextlib
|
||||||
import os
|
import os
|
||||||
import logging
|
import logging
|
||||||
import json
|
import json
|
||||||
@@ -17,10 +18,12 @@ def digest(event_id, event_metadata):
|
|||||||
|
|
||||||
with open(get_filename_for_event_id(event_id), "rb") as f:
|
with open(get_filename_for_event_id(event_id), "rb") as f:
|
||||||
event_data = json.loads(f.read().decode("utf-8"))
|
event_data = json.loads(f.read().decode("utf-8"))
|
||||||
|
opened = [get_filename_for_event_id(event_id)]
|
||||||
|
|
||||||
if event_metadata.get("has_minidump"):
|
if event_metadata.get("has_minidump"):
|
||||||
with open(get_filename_for_event_id(event_id, filetype="minidump"), "rb") as f:
|
with open(get_filename_for_event_id(event_id, filetype="minidump"), "rb") as f:
|
||||||
minidump_bytes = f.read()
|
minidump_bytes = f.read()
|
||||||
|
opened += [get_filename_for_event_id(event_id, filetype="minidump")]
|
||||||
else:
|
else:
|
||||||
minidump_bytes = None
|
minidump_bytes = None
|
||||||
|
|
||||||
@@ -29,11 +32,10 @@ def digest(event_id, event_metadata):
|
|||||||
except ValidationError as e:
|
except ValidationError as e:
|
||||||
logger.warning("ValidationError in digest_event", exc_info=e)
|
logger.warning("ValidationError in digest_event", exc_info=e)
|
||||||
finally:
|
finally:
|
||||||
# NOTE: if an SDK misbehaves, and sends the same event_id multiple times in quick succession, the line below
|
# NOTE: if an SDK misbehaves, and sends the same event_id multiple times in quick succession, the os.unlink
|
||||||
# will trigger a FileNotFoundError on the second attempt to delete the file (the files also overwrite each other
|
# below will trigger a FileNotFoundError on the second attempt to delete the file (the events also overwrite
|
||||||
# on-ingest). In that case your logs will also a "ValidationError in digest_event". Although that means an error
|
# each other on-ingest, but that's separately dealt with, showing a "ValidationError in digest_event". We're
|
||||||
# bubbles up from the below, at least for now I'm OK with that. (next steps _could_ be: [a] catching the error
|
# just catching those and ignoring them (bubble-up is not desirable because it hinders follow-up cleanups)
|
||||||
# as expected [b] refusing to "just overwrite and doubly enqueue on-ingest" [c] reporting about this particular
|
for filename in opened:
|
||||||
# problem to the end-user etc... but at least "getting it really right" might actually be quite hard (race
|
with contextlib.suppress(FileNotFoundError):
|
||||||
# conditions) and I'm not so sure it's worth it.
|
os.unlink(filename)
|
||||||
os.unlink(get_filename_for_event_id(event_id))
|
|
||||||
|
|||||||
Reference in New Issue
Block a user