Skip to content

Commit

Permalink
Handle KartonProducer load failure gracefully (#843)
Browse files Browse the repository at this point in the history
  • Loading branch information
psrok1 committed Jul 5, 2023
1 parent 8d03846 commit 57d5789
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions mwdb/core/karton.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ class KartonProducer(Producer):


if app_config.mwdb.enable_karton:
karton_producer = KartonProducer(config=KartonConfig(app_config.karton.config_path))
try:
karton_producer = KartonProducer(
config=KartonConfig(app_config.karton.config_path)
)
except Exception:
logger.exception("Failed to load Karton producer")
karton_producer = None
else:
karton_producer = None

Expand All @@ -33,9 +39,7 @@ def send_file_to_karton(file) -> str:
producer = get_karton_producer()

if producer is None:
raise RuntimeError(
"This method should not be called when Karton is not enabled"
)
raise RuntimeError("Karton is not enabled or failed to load properly")

file_stream = file.open()
try:
Expand Down Expand Up @@ -70,9 +74,7 @@ def send_config_to_karton(config) -> str:
producer = get_karton_producer()

if producer is None:
raise RuntimeError(
"This method should not be called when Karton is not enabled"
)
raise RuntimeError("Karton is not enabled or failed to load properly")

task = Task(
headers={
Expand All @@ -97,9 +99,7 @@ def send_blob_to_karton(blob) -> str:
producer = get_karton_producer()

if producer is None:
raise RuntimeError(
"This method should not be called when Karton is not enabled"
)
raise RuntimeError("Karton is not enabled or failed to load properly")

task = Task(
headers={
Expand All @@ -123,9 +123,7 @@ def get_karton_state():
producer = get_karton_producer()

if producer is None:
raise RuntimeError(
"This method should not be called when Karton is not enabled"
)
raise RuntimeError("Karton is not enabled or failed to load properly")

karton_state = KartonState(producer.backend)
return karton_state

0 comments on commit 57d5789

Please sign in to comment.