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

Celery broker_url transport options #16787

Draft
wants to merge 1 commit 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
17 changes: 17 additions & 0 deletions tests/unit/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,23 @@ def test_make_celery_app():
"redis://127.0.0.1:6379/10",
{},
),
(
Environment.production,
True,
None,
(
"rediss://user:pass@redis.example.com:6379/10"
"?socket_timeout=5&irreleveant=0"
"&ssl_cert_reqs=required&ssl_ca_certs=/p/a/t/h/cacert.pem"
),
(
"rediss://user:pass@redis.example.com:6379/10"
"?ssl_cert_reqs=required&ssl_ca_certs=/p/a/t/h/cacert.pem"
),
{
"socket_timeout": 5,
},
),
],
)
def test_includeme(
Expand Down
25 changes: 25 additions & 0 deletions warehouse/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,31 @@ def includeme(config):
"tcp_keepalive": True,
}

if broker_url.startswith("redis"):
parsed_url = urllib.parse.urlparse( # noqa: WH001, going to urlunparse this
broker_url
)
parsed_query = urllib.parse.parse_qs(parsed_url.query)

celery_transport_options = {
"socket_timeout": int,
}

for key, value in parsed_query.copy().items():
if key.startswith("ssl_"):
continue
else:
if key in celery_transport_options:
broker_transport_options[key] = celery_transport_options[key](
value[0]
)
del parsed_query[key]

parsed_url = parsed_url._replace(
query=urllib.parse.urlencode(parsed_query, doseq=True, safe="/")
)
broker_url = urllib.parse.urlunparse(parsed_url)

config.registry["celery.app"] = celery.Celery(
"warehouse", autofinalize=False, set_as_current=False
)
Expand Down