Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Try to load Karton lazily if can't be loaded eagerly #919

Merged
merged 2 commits into from
Feb 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading