From 3e20f258a2bfe48a1ff06f16a039f4bc6433146e Mon Sep 17 00:00:00 2001 From: Mingkai Dong Date: Tue, 26 Jan 2021 00:02:45 +0800 Subject: [PATCH] fix: calculate the duration for single-shot events --- aw_client/client.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/aw_client/client.py b/aw_client/client.py index ba8a6a7..e950744 100644 --- a/aw_client/client.py +++ b/aw_client/client.py @@ -234,6 +234,12 @@ def heartbeat( else: self.last_heartbeat[bucket_id] = merge else: + # If the duration is calculated in `heartbeat_merge`, + # an event that occurs only once will have a default duration + # of 0. We need to calculate the actual duration before sending + # the request. + if (last_heartbeat.duration).total_seconds() == 0: + last_heartbeat.duration = event.timestamp - last_heartbeat.timestamp data = last_heartbeat.to_json_dict() self.request_queue.add_request(endpoint, data) self.last_heartbeat[bucket_id] = event