Skip to content

Commit

Permalink
Fix: Try to load Karton lazily if can't be loaded eagerly (#919)
Browse files Browse the repository at this point in the history
  • Loading branch information
psrok1 authored Feb 27, 2024
1 parent 9c257b3 commit b198501
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions mwdb/core/karton.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,27 @@ class KartonProducer(Producer):
with_service_info = True


if app_config.mwdb.enable_karton:
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
_karton_producer = None


def get_karton_producer() -> Optional[Producer]:
return karton_producer
global _karton_producer
if not app_config.mwdb.enable_karton:
return None
if _karton_producer is None:
try:
_karton_producer = KartonProducer(
config=KartonConfig(app_config.karton.config_path)
)
except Exception:
logger.exception("Failed to load Karton producer")
_karton_producer = None
return _karton_producer


# Try to load as soon as possible, but don't give up
# if Karton is temporarily not available
get_karton_producer()


def prepare_headers(obj: "Object", arguments: Dict[str, Any]) -> Dict[str, Any]:
Expand Down

0 comments on commit b198501

Please sign in to comment.