funboost 50.1__py3-none-any.whl → 50.3__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.
Potentially problematic release.
This version of funboost might be problematic. Click here for more details.
- funboost/__init__.py +1 -1
- funboost/consumers/base_consumer.py +45 -13
- funboost/consumers/faststream_consumer.py +1 -0
- funboost/consumers/grpc_consumer.py +1 -18
- funboost/consumers/http_consumer.py +102 -35
- funboost/consumers/http_consumer_aiohttp_old.py +113 -0
- funboost/consumers/kafka_consumer.py +1 -4
- funboost/core/active_cousumer_info_getter.py +26 -4
- funboost/core/booster.py +31 -2
- funboost/core/funboost_time.py +91 -7
- funboost/core/func_params_model.py +21 -3
- funboost/core/function_result_status_saver.py +4 -4
- funboost/core/helper_funs.py +19 -5
- funboost/core/msg_result_getter.py +27 -0
- funboost/factories/broker_kind__publsiher_consumer_type_map.py +8 -3
- funboost/function_result_web/__pycache__/app.cpython-39.pyc +0 -0
- funboost/function_result_web/app.py +20 -1
- funboost/function_result_web/templates/queue_op.html +251 -43
- funboost/publishers/base_publisher.py +5 -0
- funboost/publishers/http_publisher.py +20 -2
- funboost-50.3.dist-info/METADATA +787 -0
- {funboost-50.1.dist-info → funboost-50.3.dist-info}/RECORD +26 -25
- {funboost-50.1.dist-info → funboost-50.3.dist-info}/WHEEL +1 -1
- funboost-50.1.dist-info/METADATA +0 -825
- {funboost-50.1.dist-info → funboost-50.3.dist-info}/LICENSE +0 -0
- {funboost-50.1.dist-info → funboost-50.3.dist-info}/entry_points.txt +0 -0
- {funboost-50.1.dist-info → funboost-50.3.dist-info}/top_level.txt +0 -0
funboost/core/funboost_time.py
CHANGED
|
@@ -1,22 +1,23 @@
|
|
|
1
1
|
import pytz
|
|
2
2
|
import time
|
|
3
|
-
|
|
3
|
+
import sys
|
|
4
4
|
import datetime
|
|
5
5
|
|
|
6
6
|
import typing
|
|
7
|
-
|
|
7
|
+
import threading
|
|
8
8
|
from nb_time import NbTime
|
|
9
9
|
from funboost.funboost_config_deafult import FunboostCommonConfig
|
|
10
10
|
|
|
11
|
+
|
|
11
12
|
class FunboostTime(NbTime):
|
|
12
13
|
default_formatter = NbTime.FORMATTER_DATETIME_NO_ZONE
|
|
13
14
|
|
|
14
|
-
def get_time_zone_str(self,time_zone: typing.Union[str, datetime.tzinfo,None] = None):
|
|
15
|
-
return time_zone or self.default_time_zone or
|
|
15
|
+
def get_time_zone_str(self, time_zone: typing.Union[str, datetime.tzinfo, None] = None):
|
|
16
|
+
return time_zone or self.default_time_zone or FunboostCommonConfig.TIMEZONE or self.get_localzone_name()
|
|
16
17
|
|
|
17
18
|
@staticmethod
|
|
18
|
-
def _get_tow_digist(num:int)->str:
|
|
19
|
-
if len(str(num)) ==1:
|
|
19
|
+
def _get_tow_digist(num: int) -> str:
|
|
20
|
+
if len(str(num)) == 1:
|
|
20
21
|
return f'0{num}'
|
|
21
22
|
return str(num)
|
|
22
23
|
|
|
@@ -28,9 +29,92 @@ class FunboostTime(NbTime):
|
|
|
28
29
|
return t_str
|
|
29
30
|
|
|
30
31
|
|
|
32
|
+
# 缓存时区对象,提升性能(避免重复解析)
|
|
33
|
+
_tz_cache = {}
|
|
34
|
+
|
|
35
|
+
_DIGIT_MAP = {i: f'{i:02d}' for i in range(100)}
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def _gen_2_dig_number(n):
|
|
39
|
+
return _DIGIT_MAP[n]
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def get_now_time_str_by_tz(tz_name: str = None) -> str:
|
|
43
|
+
# 生成100万次当前时间字符串%Y-%m-%d %H:%M:%S仅需1.9秒.
|
|
44
|
+
"""
|
|
45
|
+
根据时区名(如 'Asia/Shanghai')返回当前时间字符串,格式:'%Y-%m-%d %H:%M:%S'
|
|
46
|
+
|
|
47
|
+
兼容 Python 3.6+,优先使用 zoneinfo(3.9+),否则尝试 pytz
|
|
48
|
+
|
|
49
|
+
:param tz_name: IANA 时区名称,如 'Asia/Shanghai', 'America/New_York'
|
|
50
|
+
:return: 格式化时间字符串
|
|
51
|
+
"""
|
|
52
|
+
# 检查缓存
|
|
53
|
+
tz_name = tz_name or FunboostCommonConfig.TIMEZONE
|
|
54
|
+
if tz_name not in _tz_cache:
|
|
55
|
+
if sys.version_info >= (3, 9):
|
|
56
|
+
from zoneinfo import ZoneInfo
|
|
57
|
+
_tz_cache[tz_name] = ZoneInfo(tz_name)
|
|
58
|
+
else:
|
|
59
|
+
# Python < 3.9,使用 pytz
|
|
60
|
+
_tz_cache[tz_name] = pytz.timezone(tz_name)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
tz = _tz_cache[tz_name]
|
|
64
|
+
|
|
65
|
+
# 获取当前时间并格式化(注意:datetime.now(tz) 是最高效的方式)
|
|
66
|
+
now = datetime.datetime.now(tz)
|
|
67
|
+
# return f'{now.year:04d}-{now.month:02d}-{now.day:02d} {now.hour:02d}:{now.minute:02d}:{now.second:02d}'
|
|
68
|
+
# return now.strftime("%Y-%m-%d %H:%M:%S")
|
|
69
|
+
return f'{now.year}-{_gen_2_dig_number(now.month)}-{_gen_2_dig_number(now.day)} {_gen_2_dig_number(now.hour)}:{_gen_2_dig_number(now.minute)}:{_gen_2_dig_number(now.second)}'
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
class NowTimeStrCache:
|
|
73
|
+
# 生成100万次当前时间字符串%Y-%m-%d %H:%M:%S仅需0.4秒.
|
|
74
|
+
# 全局变量,用于存储缓存的时间字符串和对应的整秒时间戳
|
|
75
|
+
_cached_time_str: typing.Optional[str] = None
|
|
76
|
+
_cached_time_second: int = 0
|
|
77
|
+
|
|
78
|
+
# 为了线程安全,使用锁。在极高并发下,锁的开销远小于每毫秒都进行时间格式化。
|
|
79
|
+
_time_cache_lock = threading.Lock()
|
|
80
|
+
|
|
81
|
+
@classmethod
|
|
82
|
+
def fast_get_now_time_str(cls,timezone_str:str=None) -> str:
|
|
83
|
+
"""
|
|
84
|
+
获取当前时间字符串,格式为 '%Y-%m-%d %H:%M:%S'。
|
|
85
|
+
通过缓存机制,同一秒内的多次调用直接返回缓存结果,极大提升性能。
|
|
86
|
+
适用于对时间精度要求不高(秒级即可)的高并发场景。
|
|
87
|
+
:return: 格式化后的时间字符串,例如 '2024-06-12 15:30:45'
|
|
88
|
+
"""
|
|
89
|
+
timezone_str = timezone_str or FunboostCommonConfig.TIMEZONE
|
|
90
|
+
|
|
91
|
+
# 获取当前的整秒时间戳(去掉小数部分)
|
|
92
|
+
current_second = int(time.time())
|
|
93
|
+
|
|
94
|
+
# 如果缓存的时间戳与当前秒数一致,直接返回缓存的字符串。
|
|
95
|
+
if current_second == cls._cached_time_second:
|
|
96
|
+
return cls._cached_time_str
|
|
97
|
+
|
|
98
|
+
# 如果不一致,说明进入新的一秒,需要重新计算并更新缓存。
|
|
99
|
+
# 使用锁确保在多线程环境下,只有一个线程会执行更新操作。
|
|
100
|
+
|
|
101
|
+
with cls._time_cache_lock:
|
|
102
|
+
# 双重检查锁定 (Double-Checked Locking),防止在等待锁的过程中,其他线程已经更新了缓存。
|
|
103
|
+
if current_second == cls._cached_time_second:
|
|
104
|
+
return cls._cached_time_str
|
|
105
|
+
|
|
106
|
+
# 重新计算时间字符串。这里直接使用 time.strftime,因为它在秒级更新的场景下性能足够。
|
|
107
|
+
# 我们不需要像 Funboost 那样为每一毫秒的调用都去做查表优化。
|
|
108
|
+
now = datetime.datetime.now(tz=pytz.timezone(timezone_str))
|
|
109
|
+
cls._cached_time_str = now.strftime('%Y-%m-%d %H:%M:%S', )
|
|
110
|
+
cls._cached_time_second = current_second
|
|
111
|
+
|
|
112
|
+
return cls._cached_time_str
|
|
113
|
+
|
|
114
|
+
|
|
31
115
|
if __name__ == '__main__':
|
|
32
116
|
print(FunboostTime().get_str())
|
|
33
|
-
tz=pytz.timezone(FunboostCommonConfig.TIMEZONE)
|
|
117
|
+
tz = pytz.timezone(FunboostCommonConfig.TIMEZONE)
|
|
34
118
|
for i in range(1000000):
|
|
35
119
|
pass
|
|
36
120
|
# FunboostTime()#.get_str_fast()
|
|
@@ -201,12 +201,17 @@ class BoosterParams(BaseJsonAbleModel):
|
|
|
201
201
|
schedule_tasks_on_main_thread: bool = False # 直接在主线程调度任务,意味着不能直接在当前主线程同时开启两个消费者。
|
|
202
202
|
|
|
203
203
|
is_auto_start_consuming_message: bool = False # 是否在定义后就自动启动消费,无需用户手动写 .consume() 来启动消息消费。
|
|
204
|
+
|
|
205
|
+
# booster_group :消费分组名字, BoostersManager.consume_group 时候根据 booster_group 启动多个消费函数,减少需要写 f1.consume() f2.consume() ...这种。
|
|
206
|
+
# 不像BoostersManager.consume_all() 会启动所有不相关消费函数,也不像 f1.consume() f2.consume() 这样需要逐个启动消费函数。
|
|
207
|
+
# 可以根据业务逻辑创建不同的分组,实现灵活的消费启动策略。
|
|
208
|
+
# 用法见文档 4.2d.3 章节. 使用 BoostersManager ,通过 consume_group 启动一组消费函数
|
|
209
|
+
booster_group:typing.Union[str, None] = None
|
|
204
210
|
|
|
205
211
|
consuming_function: typing.Optional[typing.Callable] = None # 消费函数,在@boost时候不用指定,因为装饰器知道下面的函数.
|
|
206
212
|
consuming_function_raw: typing.Optional[typing.Callable] = None # 不需要传递,自动生成
|
|
207
213
|
consuming_function_name: str = '' # 不需要传递,自动生成
|
|
208
214
|
|
|
209
|
-
|
|
210
215
|
|
|
211
216
|
broker_exclusive_config: dict = {} # 加上一个不同种类中间件非通用的配置,不同中间件自身独有的配置,不是所有中间件都兼容的配置,因为框架支持30种消息队列,消息队列不仅仅是一般的先进先出queue这么简单的概念,
|
|
212
217
|
# 例如kafka支持消费者组,rabbitmq也支持各种独特概念例如各种ack机制 复杂路由机制,有的中间件原生能支持消息优先级有的中间件不支持,每一种消息队列都有独特的配置参数意义,可以通过这里传递。每种中间件能传递的键值对可以看consumer类的 BROKER_EXCLUSIVE_CONFIG_DEFAULT
|
|
@@ -228,9 +233,20 @@ class BoosterParams(BaseJsonAbleModel):
|
|
|
228
233
|
COMMON_FUNCTION = 'COMMON_FUNCTION'
|
|
229
234
|
"""
|
|
230
235
|
|
|
236
|
+
"""
|
|
237
|
+
user_options:
|
|
238
|
+
用户额外自定义的配置,高级用户或者奇葩需求可以用得到,用户可以自由发挥,存放任何设置.
|
|
239
|
+
user_options 提供了一个统一的、用户自定义的命名空间,让用户可以为自己的“奇葩需求”或“高级定制”传递配置,而无需等待框架开发者添加官方支持。
|
|
240
|
+
funboost 是自由框架不是奴役框架,不仅消费函数逻辑自由,目录层级结构自由,自定义奇葩扩展也要追求自由,用户不用改funboost BoosterParams 源码来加装饰器参数
|
|
241
|
+
|
|
242
|
+
使用场景见文档 4b.6 章节.
|
|
243
|
+
"""
|
|
244
|
+
user_options: dict = {} # 用户自定义的配置,高级用户或者奇葩需求可以用得到,用户可以自由发挥,存放任何设置.
|
|
245
|
+
|
|
246
|
+
|
|
231
247
|
auto_generate_info: dict = {} # 自动生成的信息,不需要用户主动传参.
|
|
232
|
-
|
|
233
|
-
|
|
248
|
+
|
|
249
|
+
|
|
234
250
|
|
|
235
251
|
@root_validator(skip_on_failure=True, )
|
|
236
252
|
def check_values(cls, values: dict):
|
|
@@ -358,6 +374,8 @@ class PublisherParams(BaseJsonAbleModel):
|
|
|
358
374
|
publish_msg_log_use_full_msg: bool = False # 发布到消息队列的消息内容的日志,是否显示消息的完整体,还是只显示函数入参。
|
|
359
375
|
consuming_function_kind: typing.Optional[str] = None # 自动生成的信息,不需要用户主动传参.
|
|
360
376
|
rpc_timeout: int = 1800 # rpc模式下,等待rpc结果返回的超时时间
|
|
377
|
+
user_options: dict = {} # 用户自定义的配置,高级用户或者奇葩需求可以用得到,用户可以自由发挥,存放任何设置.
|
|
378
|
+
|
|
361
379
|
|
|
362
380
|
if __name__ == '__main__':
|
|
363
381
|
from funboost.concurrent_pool import FlexibleThreadPool
|
|
@@ -14,7 +14,7 @@ import sys
|
|
|
14
14
|
from pymongo import IndexModel, ReplaceOne
|
|
15
15
|
|
|
16
16
|
from funboost.core.func_params_model import FunctionResultStatusPersistanceConfig
|
|
17
|
-
from funboost.core.helper_funs import get_publish_time, delete_keys_and_return_new_dict
|
|
17
|
+
from funboost.core.helper_funs import get_publish_time, delete_keys_and_return_new_dict, get_publish_time_format
|
|
18
18
|
from funboost.core.serialization import Serialization
|
|
19
19
|
from funboost.utils import time_util, decorators
|
|
20
20
|
from funboost.utils.mongo_util import MongoMixin
|
|
@@ -42,9 +42,9 @@ class FunctionResultStatus():
|
|
|
42
42
|
self.task_id = self.msg_dict.get('extra', {}).get('task_id', '')
|
|
43
43
|
self.process_id = os.getpid()
|
|
44
44
|
self.thread_id = threading.get_ident()
|
|
45
|
-
self.publish_time
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
self.publish_time = get_publish_time(msg_dict)
|
|
46
|
+
self.publish_time_format = get_publish_time_format(msg_dict)
|
|
47
|
+
# print(self.publish_time_format)
|
|
48
48
|
function_params = delete_keys_and_return_new_dict(msg_dict, )
|
|
49
49
|
self.params = function_params
|
|
50
50
|
self.params_str = Serialization.to_json_str(function_params)
|
funboost/core/helper_funs.py
CHANGED
|
@@ -3,7 +3,7 @@ import pytz
|
|
|
3
3
|
import time
|
|
4
4
|
import uuid
|
|
5
5
|
import datetime
|
|
6
|
-
from funboost.core.funboost_time import FunboostTime
|
|
6
|
+
from funboost.core.funboost_time import FunboostTime, get_now_time_str_by_tz, NowTimeStrCache
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
def get_publish_time(paramsx: dict):
|
|
@@ -14,6 +14,14 @@ def get_publish_time(paramsx: dict):
|
|
|
14
14
|
return paramsx.get('extra', {}).get('publish_time', None)
|
|
15
15
|
|
|
16
16
|
|
|
17
|
+
def get_publish_time_format(paramsx: dict):
|
|
18
|
+
"""
|
|
19
|
+
:param paramsx:
|
|
20
|
+
:return:
|
|
21
|
+
"""
|
|
22
|
+
return paramsx.get('extra', {}).get('publish_time_format', None)
|
|
23
|
+
|
|
24
|
+
|
|
17
25
|
def delete_keys_and_return_new_dict(dictx: dict, keys: list = None):
|
|
18
26
|
dict_new = copy.deepcopy(dictx) # 主要是去掉一级键 publish_time,浅拷贝即可。新的消息已经不是这样了。
|
|
19
27
|
keys = ['publish_time', 'publish_time_format', 'extra'] if keys is None else keys
|
|
@@ -49,13 +57,18 @@ class MsgGenerater:
|
|
|
49
57
|
def generate_publish_time() -> float:
|
|
50
58
|
return round(time.time(),4)
|
|
51
59
|
|
|
60
|
+
|
|
52
61
|
@staticmethod
|
|
53
62
|
def generate_publish_time_format() -> str:
|
|
54
|
-
return FunboostTime().get_str()
|
|
63
|
+
# return FunboostTime().get_str() # 性能不好
|
|
64
|
+
# return get_now_time_str_by_tz() # 2秒100万次
|
|
65
|
+
return NowTimeStrCache.fast_get_now_time_str() # 0.4秒100万次
|
|
66
|
+
|
|
55
67
|
|
|
56
68
|
@classmethod
|
|
57
69
|
def generate_pulish_time_and_task_id(cls,queue_name:str,task_id=None):
|
|
58
|
-
extra_params = {'task_id': task_id or cls.generate_task_id(queue_name),
|
|
70
|
+
extra_params = {'task_id': task_id or cls.generate_task_id(queue_name),
|
|
71
|
+
'publish_time': cls.generate_publish_time(),
|
|
59
72
|
'publish_time_format': cls.generate_publish_time_format()}
|
|
60
73
|
return extra_params
|
|
61
74
|
|
|
@@ -68,8 +81,9 @@ if __name__ == '__main__':
|
|
|
68
81
|
print(FunboostTime())
|
|
69
82
|
for i in range(1000000):
|
|
70
83
|
# time.time()
|
|
71
|
-
|
|
84
|
+
MsgGenerater.generate_publish_time_format()
|
|
85
|
+
# FunboostTime().get_str()
|
|
72
86
|
|
|
73
|
-
datetime.datetime.now(tz=pytz.timezone(FunboostCommonConfig.TIMEZONE)).strftime(FunboostTime.FORMATTER_DATETIME_NO_ZONE)
|
|
87
|
+
# datetime.datetime.now(tz=pytz.timezone(FunboostCommonConfig.TIMEZONE)).strftime(FunboostTime.FORMATTER_DATETIME_NO_ZONE)
|
|
74
88
|
|
|
75
89
|
print(FunboostTime())
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import asyncio
|
|
2
|
+
import threading
|
|
2
3
|
import time
|
|
3
4
|
|
|
4
5
|
import typing
|
|
@@ -278,6 +279,32 @@ class ResultFromMongo(MongoMixin):
|
|
|
278
279
|
return (self.mongo_row or {}).get('result', NO_RESULT)
|
|
279
280
|
|
|
280
281
|
|
|
282
|
+
class FutureStatusResult:
|
|
283
|
+
"""
|
|
284
|
+
用于sync_call模式的结果等待和通知
|
|
285
|
+
使用threading.Event实现同步等待
|
|
286
|
+
"""
|
|
287
|
+
def __init__(self, call_type: str):
|
|
288
|
+
self.execute_finish_event = threading.Event()
|
|
289
|
+
self.staus_result_obj: FunctionResultStatus = None
|
|
290
|
+
self.call_type = call_type # sync_call or publish
|
|
291
|
+
|
|
292
|
+
def set_finish(self):
|
|
293
|
+
"""标记任务完成"""
|
|
294
|
+
self.execute_finish_event.set()
|
|
295
|
+
|
|
296
|
+
def wait_finish(self, rpc_timeout):
|
|
297
|
+
"""等待任务完成,带超时"""
|
|
298
|
+
return self.execute_finish_event.wait(rpc_timeout)
|
|
299
|
+
|
|
300
|
+
def set_staus_result_obj(self, staus_result_obj: FunctionResultStatus):
|
|
301
|
+
"""设置任务执行结果"""
|
|
302
|
+
self.staus_result_obj = staus_result_obj
|
|
303
|
+
|
|
304
|
+
def get_staus_result_obj(self):
|
|
305
|
+
"""获取任务执行结果"""
|
|
306
|
+
return self.staus_result_obj
|
|
307
|
+
|
|
281
308
|
if __name__ == '__main__':
|
|
282
309
|
print(ResultFromMongo('test_queue77h6_result:764a1ba2-14eb-49e2-9209-ac83fc5db1e8').get_status_and_result())
|
|
283
310
|
print(ResultFromMongo('test_queue77h6_result:5cdb4386-44cc-452f-97f4-9e5d2882a7c1').get_result())
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import typing
|
|
2
2
|
|
|
3
3
|
from funboost.publishers.empty_publisher import EmptyPublisher
|
|
4
|
-
|
|
4
|
+
|
|
5
5
|
from funboost.publishers.nats_publisher import NatsPublisher
|
|
6
6
|
from funboost.publishers.peewee_publisher import PeeweePublisher
|
|
7
7
|
from funboost.publishers.redis_publisher_lpush import RedisPublisherLpush
|
|
@@ -28,7 +28,7 @@ from funboost.publishers.httpsqs_publisher import HttpsqsPublisher
|
|
|
28
28
|
from funboost.consumers.empty_consumer import EmptyConsumer
|
|
29
29
|
from funboost.consumers.redis_consumer_priority import RedisPriorityConsumer
|
|
30
30
|
from funboost.consumers.redis_pubsub_consumer import RedisPbSubConsumer
|
|
31
|
-
|
|
31
|
+
|
|
32
32
|
from funboost.consumers.kafka_consumer import KafkaConsumer
|
|
33
33
|
from funboost.consumers.local_python_queue_consumer import LocalPythonQueueConsumer
|
|
34
34
|
from funboost.consumers.mongomq_consumer import MongoMqConsumer
|
|
@@ -74,7 +74,7 @@ broker_kind__publsiher_consumer_type_map = {
|
|
|
74
74
|
BrokerEnum.HTTPSQS: (HttpsqsPublisher, HttpsqsConsumer),
|
|
75
75
|
BrokerEnum.UDP: (UDPPublisher, UDPConsumer),
|
|
76
76
|
BrokerEnum.TCP: (TCPPublisher, TCPConsumer),
|
|
77
|
-
|
|
77
|
+
|
|
78
78
|
BrokerEnum.NATS: (NatsPublisher, NatsConsumer),
|
|
79
79
|
BrokerEnum.TXT_FILE: (TxtFilePublisher, TxtFileConsumer),
|
|
80
80
|
BrokerEnum.PEEWEE: (PeeweePublisher, PeeweeConsumer),
|
|
@@ -184,6 +184,11 @@ def regist_to_funboost(broker_kind: str):
|
|
|
184
184
|
from funboost.consumers.mysql_cdc_consumer import MysqlCdcConsumer
|
|
185
185
|
from funboost.publishers.mysql_cdc_publisher import MysqlCdcPublisher
|
|
186
186
|
register_custom_broker(broker_kind, MysqlCdcPublisher, MysqlCdcConsumer)
|
|
187
|
+
|
|
188
|
+
if broker_kind == BrokerEnum.HTTP:
|
|
189
|
+
from funboost.consumers.http_consumer import HTTPConsumer
|
|
190
|
+
from funboost.publishers.http_publisher import HTTPPublisher
|
|
191
|
+
register_custom_broker(broker_kind, HTTPPublisher, HTTPConsumer)
|
|
187
192
|
|
|
188
193
|
if __name__ == '__main__':
|
|
189
194
|
import sys
|
|
Binary file
|
|
@@ -271,8 +271,27 @@ def get_time_series_data_by_queue_name(queue_name,):
|
|
|
271
271
|
|
|
272
272
|
返回例如 [{'report_data': {'pause_flag': -1, 'msg_num_in_broker': 936748, 'history_run_count': '150180', 'history_run_fail_count': '46511', 'all_consumers_last_x_s_execute_count': 7, 'all_consumers_last_x_s_execute_count_fail': 0, 'all_consumers_last_x_s_avarage_function_spend_time': 3.441, 'all_consumers_avarage_function_spend_time_from_start': 4.598, 'all_consumers_total_consume_count_from_start': 1296, 'all_consumers_total_consume_count_from_start_fail': 314, 'report_ts': 1749617360.597841}, 'report_ts': 1749617360.597841}, {'report_data': {'pause_flag': -1, 'msg_num_in_broker': 936748, 'history_run_count': '150184', 'history_run_fail_count': '46514', 'all_consumers_last_x_s_execute_count': 7, 'all_consumers_last_x_s_execute_count_fail': 0, 'all_consumers_last_x_s_avarage_function_spend_time': 3.441, 'all_consumers_avarage_function_spend_time_from_start': 4.599, 'all_consumers_total_consume_count_from_start': 1299, 'all_consumers_total_consume_count_from_start_fail': 316, 'report_ts': 1749617370.628166}, 'report_ts': 1749617370.628166}]
|
|
273
273
|
"""
|
|
274
|
+
# 获取前端传递的参数
|
|
275
|
+
start_ts = request.args.get('start_ts')
|
|
276
|
+
end_ts = request.args.get('end_ts')
|
|
277
|
+
curve_samples_count = request.args.get('curve_samples_count')
|
|
278
|
+
|
|
279
|
+
# 如果前端指定了采样点数,使用前端的值
|
|
280
|
+
if curve_samples_count:
|
|
281
|
+
try:
|
|
282
|
+
curve_samples_count = int(curve_samples_count)
|
|
283
|
+
# 验证值是否在允许的范围内
|
|
284
|
+
allowed_values = [60, 120, 180, 360, 720, 1440,8640]
|
|
285
|
+
if curve_samples_count not in allowed_values:
|
|
286
|
+
curve_samples_count = 360 # 默认值
|
|
287
|
+
except (ValueError, TypeError):
|
|
288
|
+
curve_samples_count = 360 # 默认值
|
|
289
|
+
else:
|
|
290
|
+
# 如果前端没有指定,使用默认值
|
|
291
|
+
curve_samples_count = 360
|
|
292
|
+
|
|
274
293
|
return jsonify(QueueConusmerParamsGetter().get_time_series_data_by_queue_name(
|
|
275
|
-
queue_name,
|
|
294
|
+
queue_name, start_ts, end_ts, curve_samples_count))
|
|
276
295
|
|
|
277
296
|
@app.route('/rpc/rpc_call',methods=['POST'])
|
|
278
297
|
def rpc_call():
|