File tree Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Original file line number Diff line number Diff line change 53
53
transaction_to_json ,
54
54
)
55
55
from .search import get_search_indexer , get_semantic_search_indexer
56
- from .telemetry import get_telemetry_payload , send_telemetry , update_telemetry_timestamp
56
+ from .telemetry import (
57
+ get_telemetry_payload ,
58
+ send_telemetry ,
59
+ telemetry_sent_last_24h ,
60
+ update_telemetry_timestamp ,
61
+ )
57
62
from .util import (
58
63
abort_with_message ,
59
64
check_quota_people ,
@@ -612,6 +617,13 @@ def update_search_indices_from_transaction(
612
617
@shared_task ()
613
618
def send_telemetry_task (tree : str ):
614
619
"""Send telemetry"""
620
+ if telemetry_sent_last_24h ():
621
+ # Although this task will only be called by the backend if it hasn't been
622
+ # called in the last 24 hours, we check it here again because if a server
623
+ # is misconfigured and the celery worker is run in a container that doesn't
624
+ # have access to the same persistent cache as the backend, we don't want to
625
+ # send telemetry every time a request hits the API.
626
+ return None
615
627
data = get_telemetry_payload (tree_id = tree )
616
628
# if the request fails, an exception will be raised
617
629
send_telemetry (data = data )
Original file line number Diff line number Diff line change @@ -24,6 +24,11 @@ def send_telemetry(data: dict[str, str | int | float]) -> None:
24
24
response .raise_for_status () # Raise exception for HTTP errors
25
25
26
26
27
+ def telemetry_sent_last_24h () -> bool :
28
+ """Check if telemetry has been sent in the last 24 hours."""
29
+ return time .time () - telemetry_last_sent () < 24 * 60 * 60
30
+
31
+
27
32
def should_send_telemetry () -> bool :
28
33
"""Whether telemetry should be sent."""
29
34
if current_app .config .get ("DISABLE_TELEMETRY" ):
@@ -37,7 +42,7 @@ def should_send_telemetry() -> bool:
37
42
# do not send telemetry during tests unless MOCK_TELEMETRY is set
38
43
return False
39
44
# only send telemetry if it has not been sent in the last 24 hours
40
- if time . time () - telemetry_last_sent () < 24 * 60 * 60 :
45
+ if telemetry_sent_last_24h () :
41
46
return False
42
47
return True
43
48
You can’t perform that action at this time.
0 commit comments