-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathtelemetry_sync.py
More file actions
74 lines (54 loc) · 2.33 KB
/
telemetry_sync.py
File metadata and controls
74 lines (54 loc) · 2.33 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
"""Telemetry syncrhonization task."""
import logging
from splitio.tasks import BaseSynchronizationTask
from splitio.tasks.util.asynctask import AsyncTask, AsyncTaskAsync
_LOGGER = logging.getLogger(__name__)
class TelemetrySyncTaskBase(BaseSynchronizationTask):
"""Telemetry synchronization task uses an asynctask.AsyncTask to send MTKs."""
def start(self):
"""Start executing the telemetry synchronization task."""
self._task.start()
def stop(self, event=None):
"""Stop executing the unique telemetry synchronization task."""
pass
def is_running(self):
"""
Return whether the task is running or not.
:return: True if the task is running. False otherwise.
:rtype: bool
"""
return self._task.running()
def flush(self):
"""Flush unique keys."""
_LOGGER.debug('Forcing flush execution for telemetry')
self._task.force_execution()
class TelemetrySyncTask(TelemetrySyncTaskBase):
"""Unique Telemetry task uses an asynctask.AsyncTask to send MTKs."""
def __init__(self, synchronize_telemetry, period):
"""
Class constructor.
:param synchronize_telemetry: sender
:type synchronize_telemetry: func
:param period: How many seconds to wait between subsequent unique keys pushes to the BE.
:type period: int
"""
self._task = AsyncTask(synchronize_telemetry, period,
on_stop=synchronize_telemetry)
def stop(self, event=None):
"""Stop executing the unique telemetry synchronization task."""
self._task.stop(event)
class TelemetrySyncTaskAsync(TelemetrySyncTaskBase):
"""Telemetry synchronization task uses an asynctask.AsyncTask to send MTKs."""
def __init__(self, synchronize_telemetry, period):
"""
Class constructor.
:param synchronize_telemetry: sender
:type synchronize_telemetry: func
:param period: How many seconds to wait between subsequent unique keys pushes to the BE.
:type period: int
"""
self._task = AsyncTaskAsync(synchronize_telemetry, period,
on_stop=synchronize_telemetry)
async def stop(self):
"""Stop executing the unique telemetry synchronization task."""
await self._task.stop(True)