Skip to content

Commit

Permalink
Woraround for registry resolving when restarting celery prefork workers
Browse files Browse the repository at this point in the history
  • Loading branch information
perronld committed Nov 15, 2023
1 parent e5f79a5 commit d5ed04e
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions weaver/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from bs4 import BeautifulSoup
from celery.app import Celery
from mypy_boto3_s3.literals import RegionName
from pyramid_celery import celery_app as app
from pyramid.config import Configurator
from pyramid.exceptions import ConfigurationError
from pyramid.httpexceptions import (
Expand All @@ -47,7 +48,7 @@
from pyramid.request import Request as PyramidRequest
from pyramid.response import _guess_type as guess_file_contents # noqa: W0212
from pyramid.settings import asbool, aslist
from pyramid.threadlocal import get_current_registry
from pyramid.threadlocal import get_current_registry, get_current_request
from pyramid_beaker import set_cache_regions_from_settings
from requests import HTTPError as RequestsHTTPError, Response
from requests.structures import CaseInsensitiveDict
Expand Down Expand Up @@ -469,7 +470,10 @@ def get_registry(container=None, nothrow=False):
if isinstance(container, Registry):
return container
if isinstance(container, WerkzeugRequest) or container is None:
return get_current_registry()
if get_current_request() is None:
return get_registry(app)
else:
return get_current_registry()
if nothrow:
return None
raise TypeError(f"Could not retrieve registry from container object of type [{fully_qualified_name(container)}].")
Expand Down

0 comments on commit d5ed04e

Please sign in to comment.