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

🤖 Add Initialization Check to Prevent Duplicate Setup #1273

Draft
wants to merge 3 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
15 changes: 9 additions & 6 deletions src/celery_app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,17 @@ def setup_celery_entrypoint(app: Celery):
app.on_configure.connect(init_celery_app)



@inject
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)])
from celery_app.tasks import setup_periodic_tasks

sender.on_after_finalize.connect(setup_periodic_tasks)
if not hasattr(sender, '_config_initialized'):
for k, v in config.items():
setattr(sender.conf, k, v)
bootup(start_model_loading=False, integrations=[CeleryIntegration(propagate_traces=True)])
from celery_app.tasks import setup_periodic_tasks

sender.on_after_finalize.connect(setup_periodic_tasks)
sender._config_initialized = True


setup_celery_entrypoint(celery_app)
Expand Down
14 changes: 8 additions & 6 deletions src/seer/bootup.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@ class DisablePreparedStatementConnection(Connection):
def bootup(
*, 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()
initialize_database()
initialize_models(start_model_loading)
if not hasattr(bootup, '_initialized'):
initialize_sentry_sdk(integrations)
with sentry_sdk.metrics.timing(key="seer_bootup_time"):
initialize_logs(["seer.", "celery_app."])
config.do_validation()
initialize_database()
initialize_models(start_model_loading)
bootup._initialized = True


@inject
Expand Down
14 changes: 8 additions & 6 deletions src/seer/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,16 @@ def initialize_database(
config: AppConfig = injected,
app: Flask = injected,
):
app.config["SQLALCHEMY_DATABASE_URI"] = config.DATABASE_URL
app.config["SQLALCHEMY_ENGINE_OPTIONS"] = {"connect_args": {"prepare_threshold": None}}
if not hasattr(app, '_db_initialized'):
app.config["SQLALCHEMY_DATABASE_URI"] = config.DATABASE_URL
app.config["SQLALCHEMY_ENGINE_OPTIONS"] = {"connect_args": {"prepare_threshold": None}}

db.init_app(app)
migrate.init_app(app, db)
db.init_app(app)
migrate.init_app(app, db)

with app.app_context():
Session.configure(bind=db.engine)
with app.app_context():
Session.configure(bind=db.engine)
app._db_initialized = True


class Base(DeclarativeBase):
Expand Down
Loading