File tree Expand file tree Collapse file tree 3 files changed +48
-0
lines changed Expand file tree Collapse file tree 3 files changed +48
-0
lines changed Original file line number Diff line number Diff line change @@ -16,4 +16,10 @@ unset REDIS_PORT
16
16
17
17
# Ensure all clients have a 5-second timeout.
18
18
# Configure the TLS settings for our Redis connection
19
+ # When adding parameters such as socket_timeout,
20
+ # you may need to update the broker url parsing in
21
+ # warehouse/tasks.py to apply them to celery_transport_options
22
+ # See https://docs.celeryq.dev/projects/kombu/en/stable/_modules/kombu/connection.html#Connection
23
+ # and https://docs.celeryq.dev/projects/kombu/en/stable/reference/kombu.transport.redis.html#transport-options
24
+ # for available/allowed arguments/mappings
19
25
REDIS_URL=" $REDIS_URL ?socket_timeout=5&ssl_cert_reqs=required&ssl_ca_certs=$( python -m certifi) "
Original file line number Diff line number Diff line change @@ -593,6 +593,23 @@ def test_make_celery_app():
593
593
"redis://127.0.0.1:6379/10" ,
594
594
{},
595
595
),
596
+ (
597
+ Environment .production ,
598
+ True ,
599
+ None ,
600
+ (
601
+ "rediss://user:pass@redis.example.com:6379/10"
602
+ "?socket_timeout=5&irreleveant=0"
603
+ "&ssl_cert_reqs=required&ssl_ca_certs=/p/a/t/h/cacert.pem"
604
+ ),
605
+ (
606
+ "rediss://user:pass@redis.example.com:6379/10"
607
+ "?ssl_cert_reqs=required&ssl_ca_certs=/p/a/t/h/cacert.pem"
608
+ ),
609
+ {
610
+ "socket_timeout" : 5 ,
611
+ },
612
+ ),
596
613
],
597
614
)
598
615
def test_includeme (
Original file line number Diff line number Diff line change @@ -306,6 +306,31 @@ def includeme(config):
306
306
"tcp_keepalive" : True ,
307
307
}
308
308
309
+ if broker_url .startswith ("redis" ):
310
+ parsed_url = urllib .parse .urlparse ( # noqa: WH001, going to urlunparse this
311
+ broker_url
312
+ )
313
+ parsed_query = urllib .parse .parse_qs (parsed_url .query )
314
+
315
+ celery_transport_options = {
316
+ "socket_timeout" : int ,
317
+ }
318
+
319
+ for key , value in parsed_query .copy ().items ():
320
+ if key .startswith ("ssl_" ):
321
+ continue
322
+ else :
323
+ if key in celery_transport_options :
324
+ broker_transport_options [key ] = celery_transport_options [key ](
325
+ value [0 ]
326
+ )
327
+ del parsed_query [key ]
328
+
329
+ parsed_url = parsed_url ._replace (
330
+ query = urllib .parse .urlencode (parsed_query , doseq = True , safe = "/" )
331
+ )
332
+ broker_url = urllib .parse .urlunparse (parsed_url )
333
+
309
334
config .registry ["celery.app" ] = celery .Celery (
310
335
"warehouse" , autofinalize = False , set_as_current = False
311
336
)
You can’t perform that action at this time.
0 commit comments