Skip to content

Commit d750872

Browse files
authored
Merge pull request #2290 from aboutcode-org/share-django-cache
fix: use shared cache backend across WSGI workers
2 parents bc5f2b9 + 61c4693 commit d750872

3 files changed

Lines changed: 16 additions & 5 deletions

File tree

vulnerabilities/templates/pipeline_dashboard.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,13 @@ <h1>Pipeline Dashboard</h1>
8686
worker{{ additional|pluralize }} for the {{ queue_name }} queue.">
8787
<span class="icon"><i class="fa fa-exclamation-triangle"></i></span>
8888
</span>
89-
{% elif load_factor < 1 %}
89+
{% elif additional < 1 %}
9090
<span class="has-text-weight-bold is-size-6 has-text-success has-tooltip-arrow has-tooltip-multiline has-tooltip-success"
9191
data-tooltip="{{ queue_name|capfirst }} queue perfectly balanced.">
9292
{{ load_factor|floatformat:2 }}
9393
<span class="icon"><i class="fa fa-check-circle"></i></span>
9494
</span>
95-
{% elif load_factor < 1.6 %}
95+
{% elif additional < 2 %}
9696
<span class="has-text-weight-bold is-size-6 has-text-orange has-tooltip-arrow has-tooltip-multiline has-tooltip-orange"
9797
data-tooltip="Consider adding {{ additional }} additional worker{{ additional|pluralize }} to the {{ queue_name }} queue.">
9898
{{ load_factor|floatformat:2 }}

vulnerabilities/views.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@
5959

6060
PAGE_SIZE = 10
6161

62-
CACHE_TIMEOUT = 60 * 5
63-
6462

6563
class VulnerableCodeView(View):
6664
"""
@@ -965,11 +963,12 @@ def get_queryset(self):
965963

966964
def get_context_data(self, **kwargs):
967965
context = super().get_context_data(**kwargs)
966+
cache_timeout = 60 * 10
968967
load_per_queue = cache.get("load_per_queue")
969968

970969
if load_per_queue is None:
971970
load_per_queue = compute_queue_load_factor()
972-
cache.set("load_per_queue", load_per_queue, CACHE_TIMEOUT)
971+
cache.set("load_per_queue", load_per_queue, cache_timeout)
973972

974973
context["load_per_queue"] = load_per_queue
975974
context["active_pipeline_count"] = PipelineSchedule.objects.filter(is_active=True).count()

vulnerablecode/settings.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,18 @@
402402
}
403403

404404

405+
vcio_redis_host = env.str("VULNERABLECODE_REDIS_HOST", default=None)
406+
vcio_redis_port = env.str("VULNERABLECODE_REDIS_PORT", default=None)
407+
408+
if vcio_redis_host and vcio_redis_port:
409+
CACHES = {
410+
"default": {
411+
"BACKEND": "django.core.cache.backends.redis.RedisCache",
412+
"LOCATION": f"redis://{vcio_redis_host}:{vcio_redis_port}",
413+
}
414+
}
415+
416+
405417
# FederatedCode integration
406418

407419
FEDERATEDCODE_VULNERABILITIES_REPO = env.str(

0 commit comments

Comments
 (0)