Compare commits

...

3 Commits

Author SHA1 Message Date
Kenneth Kehl
96c2b7f419 fix 2025-02-20 15:03:48 -08:00
Kenneth Kehl
b77749415f try again with at cache 2025-02-20 14:35:33 -08:00
Kenneth Kehl
2dba0015e1 try cache 2025-02-20 14:07:55 -08:00
4 changed files with 27 additions and 8 deletions

View File

@@ -65,10 +65,7 @@ def service_dashboard(service_id):
active_jobs = [job for job in job_response if job["job_status"] != "cancelled"]
sorted_jobs = sorted(active_jobs, key=lambda job: job["created_at"], reverse=True)
job_lists = [
{
**job_dict,
"finished_processing": job_is_finished(job_dict)
}
{**job_dict, "finished_processing": job_is_finished(job_dict)}
for job_dict in sorted_jobs
]
@@ -91,7 +88,7 @@ def job_is_finished(job_dict):
"technical-failure",
"temporary-failure",
"permanent-failure",
"cancelled"
"cancelled",
]
processed_count = sum(

View File

@@ -1,10 +1,15 @@
import json
from app.extensions import redis_client
from app.notify_client import NotifyAdminAPIClient, _attach_current_user
from app.notify_client import NotifyAdminAPIClient, _attach_current_user, cache
class NotificationApiClient(NotifyAdminAPIClient):
@cache.set(
"notifications-{service_id}-{job_id}-{status}-{page}-{limit_days}-{include_jobs}-{include_one_off}",
ttl_in_seconds=30,
)
def get_notifications_for_service(
self,
service_id,

View File

@@ -38,6 +38,7 @@ class ServiceAPIClient(NotifyAdminAPIClient):
"""
return self.get("/service/{0}".format(service_id))
@cache.set("service-stats-{service_id}-{limit_days}", ttl_in_seconds=30)
def get_service_statistics(self, service_id, limit_days=None):
return self.get(
"/service/{0}/statistics".format(service_id),

View File

@@ -55,8 +55,16 @@ from app.notify_client.notification_api_client import NotificationApiClient
def test_client_gets_notifications_for_service_and_job_by_page(
mocker, arguments, expected_call
):
mocker.patch(
"app.extensions.RedisClient.get",
return_value={},
)
mocker.patch("app.extensions.RedisClient.set", return_value={})
mock_get = mocker.patch(
"app.notify_client.notification_api_client.NotificationApiClient.get"
"app.notify_client.notification_api_client.NotificationApiClient.get",
return_value={},
)
NotificationApiClient().get_notifications_for_service("abcd1234", **arguments)
mock_get.assert_called_once_with(**expected_call)
@@ -102,8 +110,16 @@ def test_client_gets_notifications_for_service_and_job_by_page(
def test_client_gets_notifications_for_service_and_job_by_page_posts_for_to(
mocker, arguments, expected_call
):
mocker.patch(
"app.extensions.RedisClient.get",
return_value={},
)
mocker.patch("app.extensions.RedisClient.set", return_value={})
mock_post = mocker.patch(
"app.notify_client.notification_api_client.NotificationApiClient.post"
"app.notify_client.notification_api_client.NotificationApiClient.post",
return_value={},
)
NotificationApiClient().get_notifications_for_service("abcd1234", **arguments)
mock_post.assert_called_once_with(**expected_call)