-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathperformance_dashboard_api_client.py
More file actions
36 lines (30 loc) · 1.27 KB
/
performance_dashboard_api_client.py
File metadata and controls
36 lines (30 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from contextvars import ContextVar
from flask import current_app
from notifications_utils.local_vars import LazyLocalGetter
from werkzeug.local import LocalProxy
from app import memo_resetters
from app.notify_client import NotifyAdminAPIClient, api_client_request_session, cache
class PerformanceDashboardAPIClient(NotifyAdminAPIClient):
@cache.set("performance-stats-{start_date}-to-{end_date}", ttl_in_seconds=3600)
def get_performance_dashboard_stats(
self,
*,
start_date,
end_date,
):
return self.get(
"/performance-dashboard",
params={
"start_date": str(start_date),
"end_date": str(end_date),
},
)
_performance_dashboard_api_client_context_var: ContextVar[PerformanceDashboardAPIClient] = ContextVar(
"performance_dashboard_api_client"
)
get_performance_dashboard_api_client: LazyLocalGetter[PerformanceDashboardAPIClient] = LazyLocalGetter(
_performance_dashboard_api_client_context_var,
lambda: PerformanceDashboardAPIClient(current_app, request_session=api_client_request_session),
)
memo_resetters.append(lambda: get_performance_dashboard_api_client.clear())
performance_dashboard_api_client = LocalProxy(get_performance_dashboard_api_client)