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

🤖 Refactor Bootup Process for Celery Integration #1599

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions src/celery_app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from celery import Celery, signals
from sentry_sdk.integrations.celery import CeleryIntegration

from seer.bootup import bootup_celery
from celery_app.config import CeleryConfig
from seer.bootup import bootup
from seer.dependency_injection import inject, injected

logger = logging.getLogger(__name__)
Expand All @@ -23,7 +23,7 @@ def setup_celery_entrypoint(app: Celery):
def init_celery_app(*args: Any, sender: Celery, config: CeleryConfig = injected, **kwargs: Any):
for k, v in config.items():
setattr(sender.conf, k, v)
bootup(start_model_loading=False, integrations=[CeleryIntegration(propagate_traces=True)])
bootup_celery(integrations=[CeleryIntegration(propagate_traces=True)])
from celery_app.tasks import setup_periodic_tasks

sender.on_after_finalize.connect(setup_periodic_tasks)
Expand Down
16 changes: 15 additions & 1 deletion src/seer/bootup.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,27 @@ class DisablePreparedStatementConnection(Connection):


@inject
def bootup(
def bootup_something(
*, start_model_loading: bool, integrations: list[Integration], config: AppConfig = injected
):
initialize_sentry_sdk(integrations)
with sentry_sdk.metrics.timing(key="seer_bootup_time"):
initialize_logs(["seer.", "celery_app."])
config.do_validation()

@inject
def bootup(
*, start_model_loading: bool, integrations: list[Integration], config: AppConfig = injected
):
bootup_core(start_model_loading=start_model_loading, integrations=integrations)
initialize_database()
initialize_models(start_model_loading)

@inject
def bootup_celery(*, integrations: list[Integration], config: AppConfig = injected):
"""Celery-specific initialization that avoids database setup"""
bootup_core(start_model_loading=False, integrations=integrations)
initialize_models(start_model_loading=False)
initialize_database()
initialize_models(start_model_loading)

Expand Down
Loading