mdbq 4.0.115__tar.gz → 4.0.116__tar.gz

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.

Potentially problematic release.


This version of mdbq might be problematic. Click here for more details.

Files changed (45) hide show
  1. {mdbq-4.0.115 → mdbq-4.0.116}/PKG-INFO +1 -1
  2. mdbq-4.0.116/mdbq/__version__.py +1 -0
  3. {mdbq-4.0.115 → mdbq-4.0.116}/mdbq/redis/redis_cache.py +105 -32
  4. {mdbq-4.0.115 → mdbq-4.0.116}/mdbq.egg-info/PKG-INFO +1 -1
  5. mdbq-4.0.115/mdbq/__version__.py +0 -1
  6. {mdbq-4.0.115 → mdbq-4.0.116}/README.txt +0 -0
  7. {mdbq-4.0.115 → mdbq-4.0.116}/mdbq/__init__.py +0 -0
  8. {mdbq-4.0.115 → mdbq-4.0.116}/mdbq/auth/__init__.py +0 -0
  9. {mdbq-4.0.115 → mdbq-4.0.116}/mdbq/auth/auth_backend.py +0 -0
  10. {mdbq-4.0.115 → mdbq-4.0.116}/mdbq/auth/rate_limiter.py +0 -0
  11. {mdbq-4.0.115 → mdbq-4.0.116}/mdbq/js/__init__.py +0 -0
  12. {mdbq-4.0.115 → mdbq-4.0.116}/mdbq/js/jc.py +0 -0
  13. {mdbq-4.0.115 → mdbq-4.0.116}/mdbq/log/__init__.py +0 -0
  14. {mdbq-4.0.115 → mdbq-4.0.116}/mdbq/log/mylogger.py +0 -0
  15. {mdbq-4.0.115 → mdbq-4.0.116}/mdbq/myconf/__init__.py +0 -0
  16. {mdbq-4.0.115 → mdbq-4.0.116}/mdbq/myconf/myconf.py +0 -0
  17. {mdbq-4.0.115 → mdbq-4.0.116}/mdbq/mysql/__init__.py +0 -0
  18. {mdbq-4.0.115 → mdbq-4.0.116}/mdbq/mysql/deduplicator.py +0 -0
  19. {mdbq-4.0.115 → mdbq-4.0.116}/mdbq/mysql/mysql.py +0 -0
  20. {mdbq-4.0.115 → mdbq-4.0.116}/mdbq/mysql/s_query.py +0 -0
  21. {mdbq-4.0.115 → mdbq-4.0.116}/mdbq/mysql/unique_.py +0 -0
  22. {mdbq-4.0.115 → mdbq-4.0.116}/mdbq/mysql/uploader.py +0 -0
  23. {mdbq-4.0.115 → mdbq-4.0.116}/mdbq/other/__init__.py +0 -0
  24. {mdbq-4.0.115 → mdbq-4.0.116}/mdbq/other/download_sku_picture.py +0 -0
  25. {mdbq-4.0.115 → mdbq-4.0.116}/mdbq/other/error_handler.py +0 -0
  26. {mdbq-4.0.115 → mdbq-4.0.116}/mdbq/other/otk.py +0 -0
  27. {mdbq-4.0.115 → mdbq-4.0.116}/mdbq/other/pov_city.py +0 -0
  28. {mdbq-4.0.115 → mdbq-4.0.116}/mdbq/other/ua_sj.py +0 -0
  29. {mdbq-4.0.115 → mdbq-4.0.116}/mdbq/pbix/__init__.py +0 -0
  30. {mdbq-4.0.115 → mdbq-4.0.116}/mdbq/pbix/pbix_refresh.py +0 -0
  31. {mdbq-4.0.115 → mdbq-4.0.116}/mdbq/pbix/refresh_all.py +0 -0
  32. {mdbq-4.0.115 → mdbq-4.0.116}/mdbq/redis/__init__.py +0 -0
  33. {mdbq-4.0.115 → mdbq-4.0.116}/mdbq/redis/getredis.py +0 -0
  34. {mdbq-4.0.115 → mdbq-4.0.116}/mdbq/route/__init__.py +0 -0
  35. {mdbq-4.0.115 → mdbq-4.0.116}/mdbq/route/analytics.py +0 -0
  36. {mdbq-4.0.115 → mdbq-4.0.116}/mdbq/route/monitor.py +0 -0
  37. {mdbq-4.0.115 → mdbq-4.0.116}/mdbq/route/routes.py +0 -0
  38. {mdbq-4.0.115 → mdbq-4.0.116}/mdbq/selenium/__init__.py +0 -0
  39. {mdbq-4.0.115 → mdbq-4.0.116}/mdbq/selenium/get_driver.py +0 -0
  40. {mdbq-4.0.115 → mdbq-4.0.116}/mdbq/spider/__init__.py +0 -0
  41. {mdbq-4.0.115 → mdbq-4.0.116}/mdbq.egg-info/SOURCES.txt +0 -0
  42. {mdbq-4.0.115 → mdbq-4.0.116}/mdbq.egg-info/dependency_links.txt +0 -0
  43. {mdbq-4.0.115 → mdbq-4.0.116}/mdbq.egg-info/top_level.txt +0 -0
  44. {mdbq-4.0.115 → mdbq-4.0.116}/setup.cfg +0 -0
  45. {mdbq-4.0.115 → mdbq-4.0.116}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: mdbq
3
- Version: 4.0.115
3
+ Version: 4.0.116
4
4
  Home-page: https://pypi.org/project/mdbq
5
5
  Author: xigua,
6
6
  Author-email: 2587125111@qq.com
@@ -0,0 +1 @@
1
+ VERSION = '4.0.116'
@@ -44,7 +44,7 @@ logger = mylogger.MyLogger(
44
44
 
45
45
 
46
46
  class CacheStatsCollector:
47
- """缓存统计收集器 - 单线程同步版本"""
47
+ """缓存统计收集器 """
48
48
 
49
49
  def __init__(self, enabled: bool = True, mysql_pool=None, config: dict = None):
50
50
  self.enabled = enabled
@@ -67,10 +67,20 @@ class CacheStatsCollector:
67
67
  self.response_times = deque(maxlen=1000)
68
68
  self.namespace_stats = defaultdict(int)
69
69
 
70
- # 同步提交控制
70
+ # 定时提交控制
71
71
  self.submit_interval = self.config.get('submit_interval', 600) # 每隔N秒定时提交一次(期间有新操作时)
72
72
  self.last_submit_time = time.time()
73
73
  self.last_operation_count = 0 # 上次提交时的操作总数
74
+
75
+ # 后台定时器
76
+ self._timer = None
77
+ self._shutdown_event = threading.Event()
78
+ self._error_count = 0 # 连续错误计数
79
+ self._max_errors = 5 # 最大连续错误次数
80
+
81
+ # 启动后台定时提交
82
+ if self.enabled and self.mysql_pool:
83
+ self._start_background_timer()
74
84
 
75
85
  def record_operation(self, operation: str, response_time: float = 0, namespace: str = ""):
76
86
  """记录操作统计"""
@@ -101,15 +111,6 @@ class CacheStatsCollector:
101
111
  'operation': operation,
102
112
  'submit_error': str(submit_error)
103
113
  })
104
-
105
- logger.debug("缓存操作统计已记录", {
106
- 'operation': operation,
107
- 'response_time_ms': round(response_time, 2),
108
- 'namespace': namespace,
109
- 'process_id': self.process_id,
110
- 'old_total_operations': old_total,
111
- 'new_total_operations': self.stats['total_operations']
112
- })
113
114
  except Exception as e:
114
115
  # 统计记录失败不应影响缓存操作
115
116
  logger.error("统计记录失败,但缓存操作继续", {
@@ -119,8 +120,64 @@ class CacheStatsCollector:
119
120
  'error': str(e)
120
121
  })
121
122
 
122
- def _check_and_submit(self):
123
- """检查并提交统计数据 """
123
+ def _start_background_timer(self):
124
+ """启动后台定时提交线程"""
125
+ if self._timer is not None:
126
+ return # 已经启动
127
+
128
+ logger.debug("启动后台定时提交", {
129
+ 'instance_name': self.instance_name,
130
+ 'submit_interval': self.submit_interval
131
+ })
132
+
133
+ self._timer = threading.Timer(self.submit_interval, self._background_submit)
134
+ self._timer.daemon = True # 设置为守护线程
135
+ self._timer.start()
136
+
137
+ def _background_submit(self):
138
+ """后台定时提交方法"""
139
+ if self._shutdown_event.is_set():
140
+ return # 已关闭,不再提交
141
+
142
+ try:
143
+ # 执行提交检查(强制检查,不受时间间隔限制)
144
+ self._check_and_submit(force_check=True)
145
+ # 成功执行,重置错误计数
146
+ self._error_count = 0
147
+
148
+ except Exception as e:
149
+ self._error_count += 1
150
+ logger.error("后台定时提交失败", {
151
+ 'instance_name': self.instance_name,
152
+ 'process_id': self.process_id,
153
+ 'error': str(e),
154
+ 'error_type': type(e).__name__,
155
+ 'error_count': self._error_count,
156
+ 'max_errors': self._max_errors
157
+ })
158
+
159
+ # 如果连续错误次数过多,停止定时器
160
+ if self._error_count >= self._max_errors:
161
+ logger.error("后台定时器连续错误过多,停止定时提交", {
162
+ 'instance_name': self.instance_name,
163
+ 'process_id': self.process_id,
164
+ 'error_count': self._error_count
165
+ })
166
+ return # 不再安排下一次定时器
167
+
168
+ finally:
169
+ # 安排下一次定时提交(仅在未达到最大错误次数时)
170
+ if not self._shutdown_event.is_set() and self._error_count < self._max_errors:
171
+ self._timer = threading.Timer(self.submit_interval, self._background_submit)
172
+ self._timer.daemon = True
173
+ self._timer.start()
174
+
175
+ def _check_and_submit(self, force_check=False):
176
+ """检查并提交统计数据
177
+
178
+ Args:
179
+ force_check: 是否强制检查(用于后台定时器)
180
+ """
124
181
  if not self.mysql_pool:
125
182
  return
126
183
 
@@ -128,7 +185,9 @@ class CacheStatsCollector:
128
185
  time_since_last_submit = current_time - self.last_submit_time
129
186
 
130
187
  # 提交逻辑:每隔固定秒数且期间有新操作则提交
131
- if time_since_last_submit >= self.submit_interval:
188
+ should_check_time = force_check or time_since_last_submit >= self.submit_interval
189
+
190
+ if should_check_time:
132
191
  # 检查是否有新的操作(与上次提交时相比)
133
192
  new_operations = self.stats['total_operations'] - self.last_operation_count
134
193
 
@@ -139,29 +198,26 @@ class CacheStatsCollector:
139
198
  self.last_submit_time = current_time
140
199
  self.last_operation_count = self.stats['total_operations']
141
200
 
142
- logger.info("统计数据定时提交", {
201
+ logger.info("统计数据提交成功", {
143
202
  'instance_name': self.instance_name,
144
- 'process_id': self.process_id,
145
203
  'total_operations': self.stats['total_operations'],
146
204
  'new_operations': new_operations,
147
- 'time_since_last_submit': round(time_since_last_submit, 2),
148
- 'submit_interval': self.submit_interval
205
+ 'trigger_type': 'background_timer' if force_check else 'operation_triggered'
149
206
  })
150
207
  except Exception as e:
151
208
  logger.error("统计数据提交失败", {
152
209
  'instance_name': self.instance_name,
153
- 'process_id': self.process_id,
154
- 'error': str(e)
210
+ 'error': str(e),
211
+ 'trigger_type': 'background_timer' if force_check else 'operation_triggered'
155
212
  })
156
213
  else:
157
214
  # 无新操作,跳过提交但更新时间
158
215
  self.last_submit_time = current_time
159
- logger.debug("定时检查:期间无新操作,跳过提交", {
160
- 'instance_name': self.instance_name,
161
- 'process_id': self.process_id,
162
- 'total_operations': self.stats['total_operations'],
163
- 'time_since_last_submit': round(time_since_last_submit, 2)
164
- })
216
+ if force_check: # 仅在后台定时器触发时记录
217
+ logger.debug("后台检查:无新操作,跳过提交", {
218
+ 'instance_name': self.instance_name,
219
+ 'total_operations': self.stats['total_operations']
220
+ })
165
221
 
166
222
  def _submit_to_mysql(self):
167
223
  """同步提交统计数据到MySQL"""
@@ -171,15 +227,17 @@ class CacheStatsCollector:
171
227
  stats_data = self.get_stats()
172
228
  if not stats_data.get('enabled'):
173
229
  return
230
+
231
+ db_name = self.config.get('db_name', 'redis_stats')
232
+ table_name = self.config.get('table_name', 'cache_performance')
174
233
 
175
234
  try:
176
235
  connection = self.mysql_pool.connection()
177
236
  with connection.cursor() as cursor:
178
237
  # 选择数据库
179
- cursor.execute(f"USE `{self.config.get('db_name', 'redis_stats')}`")
238
+ cursor.execute(f"USE `{db_name}`")
180
239
 
181
240
  # 插入统计数据
182
- table_name = self.config.get('table_name', 'cache_performance')
183
241
  insert_sql = f"""
184
242
  INSERT INTO `{table_name}` (
185
243
  `日期`, `实例标识`, `主机名`, `进程ID`, `统计时间`,
@@ -212,9 +270,10 @@ class CacheStatsCollector:
212
270
  connection.close()
213
271
 
214
272
  except Exception as e:
215
- logger.error("MySQL同步提交失败", {
273
+ logger.error("MySQL提交失败", {
216
274
  'instance_name': self.instance_name,
217
- 'process_id': self.process_id,
275
+ 'database': db_name,
276
+ 'table': table_name,
218
277
  'error': str(e)
219
278
  })
220
279
  raise
@@ -246,6 +305,20 @@ class CacheStatsCollector:
246
305
  'process_id': self.process_id
247
306
  }
248
307
 
308
+ def shutdown(self):
309
+ """关闭统计收集器,停止后台定时器"""
310
+ logger.info("关闭统计收集器", {
311
+ 'instance_name': self.instance_name
312
+ })
313
+
314
+ # 设置关闭标志
315
+ self._shutdown_event.set()
316
+
317
+ # 取消定时器
318
+ if self._timer is not None:
319
+ self._timer.cancel()
320
+ self._timer = None
321
+
249
322
  def reset_stats(self):
250
323
  """重置统计数据"""
251
324
  if not self.enabled:
@@ -760,8 +833,8 @@ class SmartCacheSystem:
760
833
  self._state = CacheSystemState.SHUTDOWN
761
834
 
762
835
  if self.stats_collector:
763
- # The stats_submitter is now a CacheStatsCollector, so we call its reset_stats
764
- self.stats_collector.reset_stats()
836
+ # 关闭统计收集器(包括后台定时器)
837
+ self.stats_collector.shutdown()
765
838
 
766
839
  logger.info("缓存系统已关闭", {'instance_name': self.instance_name})
767
840
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: mdbq
3
- Version: 4.0.115
3
+ Version: 4.0.116
4
4
  Home-page: https://pypi.org/project/mdbq
5
5
  Author: xigua,
6
6
  Author-email: 2587125111@qq.com
@@ -1 +0,0 @@
1
- VERSION = '4.0.115'
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes