can't add to primary_worker_locks if it doesn't exist (#2903)

* can't add to primary_worker_locks if it doesn't exist

* move init
This commit is contained in:
rkuo-danswer 2024-10-24 14:49:18 -07:00 committed by GitHub
parent 4bce143d6e
commit 94b4dc1656
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -78,6 +78,8 @@ def on_worker_init(sender: Any, **kwargs: Any) -> None:
logger.info("Running as the primary celery worker.")
sender.primary_worker_locks = {}
# This is singleton work that should be done on startup exactly once
# by the primary worker
tenant_ids = get_all_tenant_ids()
@ -106,6 +108,7 @@ def on_worker_init(sender: Any, **kwargs: Any) -> None:
logger.error("Primary worker lock: Acquire failed!")
raise WorkerShutdown("Primary worker lock could not be acquired!")
# tacking on our own user data to the sender
sender.primary_worker_locks[tenant_id] = lock
# As currently designed, when this worker starts as "primary", we reinitialize redis