Repository navigation
Expand file tree
/
Copy pathimpressions_sync.py
More file actions
141 lines (99 loc) · 4.34 KB
/
Copy pathimpressions_sync.py
File metadata and controls
141 lines (99 loc) · 4.34 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
"""Impressions syncrhonization task."""
import logging
from splitio.tasks import BaseSynchronizationTask
from splitio.tasks.util.asynctask import AsyncTask, AsyncTaskAsync
_LOGGER = logging.getLogger(__name__)
class ImpressionsSyncTaskBase(BaseSynchronizationTask):
"""Impressions synchronization task uses an asynctask.AsyncTask to send impressions."""
def start(self):
"""Start executing the impressions synchronization task."""
self._task.start()
def stop(self, event=None):
"""Stop executing the impressions 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 impressions in storage."""
_LOGGER.debug('Forcing flush execution for impressions')
self._task.force_execution()
class ImpressionsSyncTask(ImpressionsSyncTaskBase):
"""Impressions synchronization task uses an asynctask.AsyncTask to send impressions."""
def __init__(self, synchronize_impressions, period):
"""
Class constructor.
:param synchronize_impressions: sender
:type synchronize_impressions: func
:param period: How many seconds to wait between subsequent impressions pushes to the BE.
:type period: int
"""
self._period = period
self._task = AsyncTask(synchronize_impressions, self._period,
on_stop=synchronize_impressions)
def stop(self, event=None):
"""Stop executing the impressions synchronization task."""
self._task.stop(event)
class ImpressionsSyncTaskAsync(ImpressionsSyncTaskBase):
"""Impressions synchronization task uses an asynctask.AsyncTask to send impressions."""
def __init__(self, synchronize_impressions, period):
"""
Class constructor.
:param synchronize_impressions: sender
:type synchronize_impressions: func
:param period: How many seconds to wait between subsequent impressions pushes to the BE.
:type period: int
"""
self._period = period
self._task = AsyncTaskAsync(synchronize_impressions, self._period,
on_stop=synchronize_impressions)
async def stop(self, event=None):
"""Stop executing the impressions synchronization task."""
await self._task.stop(True)
class ImpressionsCountSyncTaskBase(BaseSynchronizationTask):
"""Impressions synchronization task uses an asynctask.AsyncTask to send impressions."""
_PERIOD = 1800 # 30 * 60 # 30 minutes
def start(self):
"""Start executing the impressions synchronization task."""
self._task.start()
def stop(self, event=None):
"""Stop executing the impressions 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 impressions in storage."""
self._task.force_execution()
class ImpressionsCountSyncTask(ImpressionsCountSyncTaskBase):
"""Impressions synchronization task uses an asynctask.AsyncTask to send impressions."""
def __init__(self, synchronize_counters):
"""
Class constructor.
:param synchronize_counters: Handler
:type synchronize_counters: func
"""
self._task = AsyncTask(synchronize_counters, self._PERIOD, on_stop=synchronize_counters)
def stop(self, event=None):
"""Stop executing the impressions synchronization task."""
self._task.stop(event)
class ImpressionsCountSyncTaskAsync(ImpressionsCountSyncTaskBase):
"""Impressions synchronization task uses an asynctask.AsyncTask to send impressions."""
def __init__(self, synchronize_counters):
"""
Class constructor.
:param synchronize_counters: Handler
:type synchronize_counters: func
"""
self._task = AsyncTaskAsync(synchronize_counters, self._PERIOD, on_stop=synchronize_counters)
async def stop(self):
"""Stop executing the impressions synchronization task."""
await self._task.stop(True)