22import logging
33
44from splitio .tasks import BaseSynchronizationTask
5- from splitio .tasks .util .asynctask import AsyncTask
5+ from splitio .tasks .util .asynctask import AsyncTask , AsyncTaskAsync
66
77_LOGGER = logging .getLogger (__name__ )
88
9- class TelemetrySyncTask (BaseSynchronizationTask ):
10- """Unique Keys synchronization task uses an asynctask.AsyncTask to send MTKs."""
9+ class TelemetrySyncTaskBase (BaseSynchronizationTask ):
10+ """Telemetry synchronization task uses an asynctask.AsyncTask to send MTKs."""
11+
12+ def start (self ):
13+ """Start executing the telemetry synchronization task."""
14+ self ._task .start ()
15+
16+ def stop (self , event = None ):
17+ """Stop executing the unique telemetry synchronization task."""
18+ pass
19+
20+ def is_running (self ):
21+ """
22+ Return whether the task is running or not.
23+
24+ :return: True if the task is running. False otherwise.
25+ :rtype: bool
26+ """
27+ return self ._task .running ()
28+
29+ def flush (self ):
30+ """Flush unique keys."""
31+ _LOGGER .debug ('Forcing flush execution for telemetry' )
32+ self ._task .force_execution ()
33+
34+
35+ class TelemetrySyncTask (TelemetrySyncTaskBase ):
36+ """Unique Telemetry task uses an asynctask.AsyncTask to send MTKs."""
1137
1238 def __init__ (self , synchronize_telemetry , period ):
1339 """
@@ -22,24 +48,27 @@ def __init__(self, synchronize_telemetry, period):
2248 self ._task = AsyncTask (synchronize_telemetry , period ,
2349 on_stop = synchronize_telemetry )
2450
25- def start (self ):
26- """Start executing the telemetry synchronization task."""
27- self ._task .start ()
28-
2951 def stop (self , event = None ):
3052 """Stop executing the unique telemetry synchronization task."""
3153 self ._task .stop (event )
3254
33- def is_running (self ):
55+
56+ class TelemetrySyncTaskAsync (TelemetrySyncTaskBase ):
57+ """Telemetry synchronization task uses an asynctask.AsyncTask to send MTKs."""
58+
59+ def __init__ (self , synchronize_telemetry , period ):
3460 """
35- Return whether the task is running or not .
61+ Class constructor .
3662
37- :return: True if the task is running. False otherwise.
38- :rtype: bool
63+ :param synchronize_telemetry: sender
64+ :type synchronize_telemetry: func
65+ :param period: How many seconds to wait between subsequent unique keys pushes to the BE.
66+ :type period: int
3967 """
40- return self ._task .running ()
4168
42- def flush (self ):
43- """Flush unique keys."""
44- _LOGGER .debug ('Forcing flush execution for telemetry' )
45- self ._task .force_execution ()
69+ self ._task = AsyncTaskAsync (synchronize_telemetry , period ,
70+ on_stop = synchronize_telemetry )
71+
72+ async def stop (self ):
73+ """Stop executing the unique telemetry synchronization task."""
74+ await self ._task .stop (True )
0 commit comments