vnai 2.1.7__py3-none-any.whl → 2.1.9__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- vnai/__init__.py +167 -178
- vnai/beam/__init__.py +2 -2
- vnai/beam/metrics.py +166 -166
- vnai/beam/pulse.py +78 -78
- vnai/beam/quota.py +332 -332
- vnai/flow/__init__.py +1 -1
- vnai/flow/queue.py +99 -99
- vnai/flow/relay.py +340 -355
- vnai/scope/__init__.py +3 -3
- vnai/scope/profile.py +578 -578
- vnai/scope/promo.py +292 -277
- vnai/scope/state.py +154 -154
- {vnai-2.1.7.dist-info → vnai-2.1.9.dist-info}/METADATA +20 -20
- vnai-2.1.9.dist-info/RECORD +16 -0
- vnai-2.1.7.dist-info/RECORD +0 -16
- {vnai-2.1.7.dist-info → vnai-2.1.9.dist-info}/WHEEL +0 -0
- {vnai-2.1.7.dist-info → vnai-2.1.9.dist-info}/top_level.txt +0 -0
vnai/flow/relay.py
CHANGED
@@ -1,356 +1,341 @@
|
|
1
|
-
import time
|
2
|
-
import threading
|
3
|
-
import json
|
4
|
-
import random
|
5
|
-
import requests
|
6
|
-
from datetime import datetime
|
7
|
-
from pathlib import Path
|
8
|
-
from typing import Dict, List, Any, Optional
|
9
|
-
|
10
|
-
class Conduit:
|
11
|
-
_instance = None
|
12
|
-
_lock = threading.Lock()
|
13
|
-
|
14
|
-
def __new__(cls,
|
15
|
-
with cls._lock:
|
16
|
-
if cls._instance is None:
|
17
|
-
cls._instance = super(Conduit, cls).__new__(cls)
|
18
|
-
cls._instance._initialize(
|
19
|
-
return cls._instance
|
20
|
-
|
21
|
-
def _initialize(self,
|
22
|
-
self.
|
23
|
-
self.
|
24
|
-
self.
|
25
|
-
|
26
|
-
"
|
27
|
-
"
|
28
|
-
|
29
|
-
|
30
|
-
self.
|
31
|
-
self.
|
32
|
-
self.
|
33
|
-
self.
|
34
|
-
self.
|
35
|
-
self.project_dir
|
36
|
-
self.project_dir
|
37
|
-
self.data_dir
|
38
|
-
self.data_dir.
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
self.
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
import
|
51
|
-
import
|
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
|
-
trigger_reason
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
if isinstance(package, dict) and"
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
if
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
self.
|
186
|
-
elif package_type =="
|
187
|
-
self.
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
"
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
"
|
243
|
-
"
|
244
|
-
|
245
|
-
|
246
|
-
self.
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
self.
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
"
|
263
|
-
"
|
264
|
-
"
|
265
|
-
"
|
266
|
-
"
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
conduit.
|
323
|
-
|
324
|
-
def
|
325
|
-
record = {
|
326
|
-
"
|
327
|
-
"
|
328
|
-
"
|
329
|
-
"
|
330
|
-
"
|
331
|
-
"timestamp": datetime.now().isoformat(),
|
332
|
-
"
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
"
|
339
|
-
|
340
|
-
|
341
|
-
"status_code": status_code,
|
342
|
-
"execution_time": execution_time,
|
343
|
-
"timestamp": datetime.now().isoformat(),
|
344
|
-
"request_size": request_size,
|
345
|
-
"response_size": response_size
|
346
|
-
}
|
347
|
-
conduit.add_api_request(record)
|
348
|
-
|
349
|
-
def configure(webhook_url):
|
350
|
-
return conduit.configure(webhook_url)
|
351
|
-
|
352
|
-
def sync_now():
|
353
|
-
return conduit.dispatch("manual")
|
354
|
-
|
355
|
-
def retry_failed():
|
1
|
+
import time
|
2
|
+
import threading
|
3
|
+
import json
|
4
|
+
import random
|
5
|
+
import requests
|
6
|
+
from datetime import datetime
|
7
|
+
from pathlib import Path
|
8
|
+
from typing import Dict, List, Any, Optional
|
9
|
+
|
10
|
+
class Conduit:
|
11
|
+
_instance = None
|
12
|
+
_lock = threading.Lock()
|
13
|
+
|
14
|
+
def __new__(cls, buffer_size=50, sync_interval=300):
|
15
|
+
with cls._lock:
|
16
|
+
if cls._instance is None:
|
17
|
+
cls._instance = super(Conduit, cls).__new__(cls)
|
18
|
+
cls._instance._initialize(buffer_size, sync_interval)
|
19
|
+
return cls._instance
|
20
|
+
|
21
|
+
def _initialize(self, buffer_size, sync_interval):
|
22
|
+
self.buffer_size = buffer_size
|
23
|
+
self.sync_interval = sync_interval
|
24
|
+
self.buffer = {
|
25
|
+
"function_calls": [],
|
26
|
+
"api_requests": [],
|
27
|
+
"rate_limits": []
|
28
|
+
}
|
29
|
+
self.lock = threading.Lock()
|
30
|
+
self.last_sync_time = time.time()
|
31
|
+
self.sync_count = 0
|
32
|
+
self.failed_queue = []
|
33
|
+
self.home_dir = Path.home()
|
34
|
+
self.project_dir = self.home_dir /".vnstock"
|
35
|
+
self.project_dir.mkdir(exist_ok=True)
|
36
|
+
self.data_dir = self.project_dir /'data'
|
37
|
+
self.data_dir.mkdir(exist_ok=True)
|
38
|
+
self.config_path = self.data_dir /"relay_config.json"
|
39
|
+
try:
|
40
|
+
from vnai.scope.profile import inspector
|
41
|
+
self.machine_id = inspector.fingerprint()
|
42
|
+
except:
|
43
|
+
self.machine_id = self._generate_fallback_id()
|
44
|
+
self._load_config()
|
45
|
+
self._start_periodic_sync()
|
46
|
+
|
47
|
+
def _generate_fallback_id(self) -> str:
|
48
|
+
try:
|
49
|
+
import platform
|
50
|
+
import hashlib
|
51
|
+
import uuid
|
52
|
+
system_info = platform.node() + platform.platform() + platform.processor()
|
53
|
+
return hashlib.md5(system_info.encode()).hexdigest()
|
54
|
+
except:
|
55
|
+
import uuid
|
56
|
+
return str(uuid.uuid4())
|
57
|
+
|
58
|
+
def _load_config(self):
|
59
|
+
if self.config_path.exists():
|
60
|
+
try:
|
61
|
+
with open(self.config_path,'r') as f:
|
62
|
+
config = json.load(f)
|
63
|
+
if'buffer_size' in config:
|
64
|
+
self.buffer_size = config['buffer_size']
|
65
|
+
if'sync_interval' in config:
|
66
|
+
self.sync_interval = config['sync_interval']
|
67
|
+
if'last_sync_time' in config:
|
68
|
+
self.last_sync_time = config['last_sync_time']
|
69
|
+
if'sync_count' in config:
|
70
|
+
self.sync_count = config['sync_count']
|
71
|
+
except:
|
72
|
+
pass
|
73
|
+
|
74
|
+
def _save_config(self):
|
75
|
+
config = {
|
76
|
+
'buffer_size': self.buffer_size,
|
77
|
+
'sync_interval': self.sync_interval,
|
78
|
+
'last_sync_time': self.last_sync_time,
|
79
|
+
'sync_count': self.sync_count
|
80
|
+
}
|
81
|
+
try:
|
82
|
+
with open(self.config_path,'w') as f:
|
83
|
+
json.dump(config, f)
|
84
|
+
except:
|
85
|
+
pass
|
86
|
+
|
87
|
+
def _start_periodic_sync(self):
|
88
|
+
def periodic_sync():
|
89
|
+
while True:
|
90
|
+
time.sleep(self.sync_interval)
|
91
|
+
self.dispatch("periodic")
|
92
|
+
sync_thread = threading.Thread(target=periodic_sync, daemon=True)
|
93
|
+
sync_thread.start()
|
94
|
+
|
95
|
+
def add_function_call(self, record):
|
96
|
+
if not isinstance(record, dict):
|
97
|
+
record = {"value": str(record)}
|
98
|
+
with self.lock:
|
99
|
+
self.buffer["function_calls"].append(record)
|
100
|
+
self._check_triggers("function_calls")
|
101
|
+
|
102
|
+
def add_api_request(self, record):
|
103
|
+
if not isinstance(record, dict):
|
104
|
+
record = {"value": str(record)}
|
105
|
+
with self.lock:
|
106
|
+
self.buffer["api_requests"].append(record)
|
107
|
+
self._check_triggers("api_requests")
|
108
|
+
|
109
|
+
def add_rate_limit(self, record):
|
110
|
+
if not isinstance(record, dict):
|
111
|
+
record = {"value": str(record)}
|
112
|
+
with self.lock:
|
113
|
+
self.buffer["rate_limits"].append(record)
|
114
|
+
self._check_triggers("rate_limits")
|
115
|
+
|
116
|
+
def _check_triggers(self, record_type: str):
|
117
|
+
current_time = time.time()
|
118
|
+
should_trigger = False
|
119
|
+
trigger_reason = None
|
120
|
+
total_records = sum(len(buffer) for buffer in self.buffer.values())
|
121
|
+
if total_records >= self.buffer_size:
|
122
|
+
should_trigger = True
|
123
|
+
trigger_reason ="buffer_full"
|
124
|
+
elif record_type =="rate_limits" and self.buffer["rate_limits"] and any(item.get("is_exceeded") for item in self.buffer["rate_limits"] if isinstance(item, dict)):
|
125
|
+
should_trigger = True
|
126
|
+
trigger_reason ="rate_limit_exceeded"
|
127
|
+
elif record_type =="function_calls" and self.buffer["function_calls"] and any(not item.get("success") for item in self.buffer["function_calls"] if isinstance(item, dict)):
|
128
|
+
should_trigger = True
|
129
|
+
trigger_reason ="function_error"
|
130
|
+
else:
|
131
|
+
time_factor = min(1.0, (current_time - self.last_sync_time) / (self.sync_interval / 2))
|
132
|
+
if random.random() < 0.05 * time_factor:
|
133
|
+
should_trigger = True
|
134
|
+
trigger_reason ="random_time_weighted"
|
135
|
+
if should_trigger:
|
136
|
+
threading.Thread(
|
137
|
+
target=self.dispatch,
|
138
|
+
args=(trigger_reason,),
|
139
|
+
daemon=True
|
140
|
+
).start()
|
141
|
+
|
142
|
+
def queue(self, package, priority=None):
|
143
|
+
try:
|
144
|
+
from vnai.scope.promo import ContentManager
|
145
|
+
is_paid = ContentManager().is_paid_user
|
146
|
+
segment_val ="paid" if is_paid else"free"
|
147
|
+
except Exception:
|
148
|
+
segment_val ="free"
|
149
|
+
|
150
|
+
def ensure_segment(d):
|
151
|
+
if not isinstance(d, dict):
|
152
|
+
return d
|
153
|
+
d = dict(d)
|
154
|
+
if"segment" not in d:
|
155
|
+
d["segment"] = segment_val
|
156
|
+
return d
|
157
|
+
if isinstance(package, dict) and"segment" not in package:
|
158
|
+
import base64
|
159
|
+
api_key = base64.b64decode("MXlJOEtnYXJudFFyMHB0cmlzZUhoYjRrZG9ta2VueU5JOFZQaXlrNWFvVQ==").decode()
|
160
|
+
package["segment"] = segment_val
|
161
|
+
if isinstance(package, dict) and isinstance(package.get("data"), dict):
|
162
|
+
if"segment" not in package["data"]:
|
163
|
+
package["data"]["segment"] = segment_val
|
164
|
+
"""Queue data package"""
|
165
|
+
if not package:
|
166
|
+
return False
|
167
|
+
if not isinstance(package, dict):
|
168
|
+
self.add_function_call(ensure_segment({"message": str(package)}))
|
169
|
+
return True
|
170
|
+
if"timestamp" not in package:
|
171
|
+
package["timestamp"] = datetime.now().isoformat()
|
172
|
+
if"type" in package:
|
173
|
+
package_type = package["type"]
|
174
|
+
data = package.get("data", {})
|
175
|
+
if isinstance(data, dict) and"system" in data:
|
176
|
+
machine_id = data["system"].get("machine_id")
|
177
|
+
data.pop("system")
|
178
|
+
if machine_id:
|
179
|
+
data["machine_id"] = machine_id
|
180
|
+
if package_type =="function":
|
181
|
+
self.add_function_call(ensure_segment(data))
|
182
|
+
elif package_type =="api_request":
|
183
|
+
self.add_api_request(ensure_segment(data))
|
184
|
+
elif package_type =="rate_limit":
|
185
|
+
self.add_rate_limit(ensure_segment(data))
|
186
|
+
elif package_type =="system_info":
|
187
|
+
self.add_function_call({
|
188
|
+
"type":"system_info",
|
189
|
+
"commercial": data.get("commercial"),
|
190
|
+
"packages": data.get("packages"),
|
191
|
+
"timestamp": package.get("timestamp")
|
192
|
+
})
|
193
|
+
elif package_type =="metrics":
|
194
|
+
metrics_data = data
|
195
|
+
for metric_type, metrics_list in metrics_data.items():
|
196
|
+
if isinstance(metrics_list, list):
|
197
|
+
if metric_type =="function":
|
198
|
+
for item in metrics_list:
|
199
|
+
self.add_function_call(ensure_segment(item))
|
200
|
+
elif metric_type =="rate_limit":
|
201
|
+
for item in metrics_list:
|
202
|
+
self.add_rate_limit(ensure_segment(item))
|
203
|
+
elif metric_type =="request":
|
204
|
+
for item in metrics_list:
|
205
|
+
self.add_api_request(ensure_segment(item))
|
206
|
+
else:
|
207
|
+
if isinstance(data, dict) and data is not package:
|
208
|
+
self.add_function_call(ensure_segment(data))
|
209
|
+
else:
|
210
|
+
self.add_function_call(ensure_segment(package))
|
211
|
+
else:
|
212
|
+
self.add_function_call(ensure_segment(package))
|
213
|
+
if priority =="high":
|
214
|
+
self.dispatch("high_priority")
|
215
|
+
return True
|
216
|
+
|
217
|
+
def _send_data(self, payload):
|
218
|
+
import base64
|
219
|
+
api_key = base64.b64decode("MXlJOEtnYXJudFFyMHB0cmlzZUhoYjRrZG9ta2VueU5JOFZQaXlrNWFvVQ==").decode()
|
220
|
+
url ="https://hq.vnstocks.com/analytics"
|
221
|
+
headers = {
|
222
|
+
"x-api-key": api_key,
|
223
|
+
"Content-Type":"application/json"
|
224
|
+
}
|
225
|
+
try:
|
226
|
+
response = requests.post(url, json=payload, headers=headers, timeout=5)
|
227
|
+
return response.status_code == 200
|
228
|
+
except Exception:
|
229
|
+
return False
|
230
|
+
|
231
|
+
def dispatch(self, reason="manual"):
|
232
|
+
with self.lock:
|
233
|
+
if all(len(records) == 0 for records in self.buffer.values()):
|
234
|
+
return False
|
235
|
+
data_to_send = {
|
236
|
+
"function_calls": self.buffer["function_calls"].copy(),
|
237
|
+
"api_requests": self.buffer["api_requests"].copy(),
|
238
|
+
"rate_limits": self.buffer["rate_limits"].copy()
|
239
|
+
}
|
240
|
+
self.buffer = {
|
241
|
+
"function_calls": [],
|
242
|
+
"api_requests": [],
|
243
|
+
"rate_limits": []
|
244
|
+
}
|
245
|
+
self.last_sync_time = time.time()
|
246
|
+
self.sync_count += 1
|
247
|
+
self._save_config()
|
248
|
+
try:
|
249
|
+
from vnai.scope.profile import inspector
|
250
|
+
environment_info = inspector.examine()
|
251
|
+
machine_id = environment_info.get("machine_id", self.machine_id)
|
252
|
+
except:
|
253
|
+
environment_info = {"machine_id": self.machine_id}
|
254
|
+
machine_id = self.machine_id
|
255
|
+
payload = {
|
256
|
+
"analytics_data": data_to_send,
|
257
|
+
"metadata": {
|
258
|
+
"timestamp": datetime.now().isoformat(),
|
259
|
+
"machine_id": machine_id,
|
260
|
+
"sync_count": self.sync_count,
|
261
|
+
"trigger_reason": reason,
|
262
|
+
"environment": environment_info,
|
263
|
+
"data_counts": {
|
264
|
+
"function_calls": len(data_to_send["function_calls"]),
|
265
|
+
"api_requests": len(data_to_send["api_requests"]),
|
266
|
+
"rate_limits": len(data_to_send["rate_limits"])
|
267
|
+
}
|
268
|
+
}
|
269
|
+
}
|
270
|
+
success = self._send_data(payload)
|
271
|
+
if not success:
|
272
|
+
with self.lock:
|
273
|
+
self.failed_queue.append(payload)
|
274
|
+
if len(self.failed_queue) > 10:
|
275
|
+
self.failed_queue = self.failed_queue[-10:]
|
276
|
+
with self.lock:
|
277
|
+
to_retry = self.failed_queue.copy()
|
278
|
+
self.failed_queue = []
|
279
|
+
success_count = 0
|
280
|
+
for payload in to_retry:
|
281
|
+
if self._send_data(payload):
|
282
|
+
success_count += 1
|
283
|
+
else:
|
284
|
+
with self.lock:
|
285
|
+
self.failed_queue.append(payload)
|
286
|
+
return success_count
|
287
|
+
conduit = Conduit()
|
288
|
+
|
289
|
+
def track_function_call(function_name, source, execution_time, success=True, error=None, args=None):
|
290
|
+
record = {
|
291
|
+
"function": function_name,
|
292
|
+
"source": source,
|
293
|
+
"execution_time": execution_time,
|
294
|
+
"timestamp": datetime.now().isoformat(),
|
295
|
+
"success": success
|
296
|
+
}
|
297
|
+
if error:
|
298
|
+
record["error"] = error
|
299
|
+
if args:
|
300
|
+
sanitized_args = {}
|
301
|
+
if isinstance(args, dict):
|
302
|
+
for key, value in args.items():
|
303
|
+
if isinstance(value, (str, int, float, bool)):
|
304
|
+
sanitized_args[key] = value
|
305
|
+
else:
|
306
|
+
sanitized_args[key] = str(type(value))
|
307
|
+
else:
|
308
|
+
sanitized_args = {"value": str(args)}
|
309
|
+
record["args"] = sanitized_args
|
310
|
+
conduit.add_function_call(record)
|
311
|
+
|
312
|
+
def track_rate_limit(source, limit_type, limit_value, current_usage, is_exceeded):
|
313
|
+
record = {
|
314
|
+
"source": source,
|
315
|
+
"limit_type": limit_type,
|
316
|
+
"limit_value": limit_value,
|
317
|
+
"current_usage": current_usage,
|
318
|
+
"is_exceeded": is_exceeded,
|
319
|
+
"timestamp": datetime.now().isoformat(),
|
320
|
+
"usage_percentage": (current_usage / limit_value) * 100 if limit_value > 0 else 0
|
321
|
+
}
|
322
|
+
conduit.add_rate_limit(record)
|
323
|
+
|
324
|
+
def track_api_request(endpoint, source, method, status_code, execution_time, request_size=0, response_size=0):
|
325
|
+
record = {
|
326
|
+
"endpoint": endpoint,
|
327
|
+
"source": source,
|
328
|
+
"method": method,
|
329
|
+
"status_code": status_code,
|
330
|
+
"execution_time": execution_time,
|
331
|
+
"timestamp": datetime.now().isoformat(),
|
332
|
+
"request_size": request_size,
|
333
|
+
"response_size": response_size
|
334
|
+
}
|
335
|
+
conduit.add_api_request(record)
|
336
|
+
|
337
|
+
def sync_now():
|
338
|
+
return conduit.dispatch("manual")
|
339
|
+
|
340
|
+
def retry_failed():
|
356
341
|
return conduit.retry_failed()
|