funboost 44.1__py3-none-any.whl → 44.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 +25 -15
- funboost/consumers/http_consumer.py +10 -10
- funboost/consumers/http_consumer000.py +1 -2
- funboost/consumers/httpsqs_consumer.py +1 -1
- funboost/consumers/kafka_consumer.py +13 -15
- funboost/consumers/kafka_consumer_manually_commit.py +12 -15
- funboost/consumers/kombu_consumer.py +0 -1
- funboost/consumers/local_python_queue_consumer.py +2 -3
- funboost/consumers/memory_deque_consumer.py +0 -3
- funboost/consumers/mongomq_consumer.py +0 -1
- funboost/consumers/mqtt_consumer.py +4 -3
- funboost/consumers/nats_consumer.py +6 -5
- funboost/consumers/nsq_consumer.py +7 -6
- funboost/consumers/peewee_conusmer.py +1 -2
- funboost/consumers/persist_queue_consumer.py +1 -2
- funboost/consumers/pulsar_consumer.py +1 -2
- funboost/consumers/rabbitmq_amqpstorm_consumer.py +0 -2
- funboost/consumers/rabbitmq_pika_consumer.py +0 -2
- funboost/consumers/rabbitmq_pika_consumerv0.py +0 -1
- funboost/consumers/rabbitmq_rabbitpy_consumer.py +1 -2
- funboost/consumers/redis_brpoplpush_consumer.py +1 -3
- funboost/consumers/redis_consumer.py +4 -8
- funboost/consumers/redis_consumer_ack_able.py +5 -10
- funboost/consumers/redis_consumer_priority.py +3 -7
- funboost/consumers/redis_consumer_simple.py +2 -3
- funboost/consumers/redis_pubsub_consumer.py +3 -3
- funboost/consumers/redis_stream_consumer.py +3 -3
- funboost/consumers/rocketmq_consumer.py +2 -2
- funboost/consumers/sqlachemy_consumer.py +1 -1
- funboost/consumers/tcp_consumer.py +2 -2
- funboost/consumers/txt_file_consumer.py +2 -2
- funboost/consumers/udp_consumer.py +2 -2
- funboost/consumers/zeromq_consumer.py +13 -13
- funboost/core/cli/discovery_boosters.py +2 -2
- funboost/core/funboost_config_getter.py +7 -0
- funboost/core/funboost_time.py +28 -0
- funboost/core/helper_funs.py +21 -9
- funboost/core/lazy_impoter.py +108 -33
- funboost/core/loggers.py +1 -1
- funboost/core/muliti_process_enhance.py +3 -3
- funboost/function_result_web/app.py +3 -0
- funboost/function_result_web/functions.py +0 -1
- funboost/publishers/base_publisher.py +4 -7
- funboost/publishers/confluent_kafka_publisher.py +9 -12
- funboost/publishers/kafka_publisher.py +5 -11
- funboost/publishers/mqtt_publisher.py +3 -2
- funboost/publishers/nats_publisher.py +2 -2
- funboost/publishers/nsq_publisher.py +4 -6
- funboost/publishers/zeromq_publisher.py +3 -3
- funboost/set_frame_config.py +1 -1
- funboost/utils/bulk_operation.py +3 -2
- funboost/utils/decorators.py +14 -2
- funboost/utils/paramiko_util.py +1 -1
- funboost/utils/resource_monitoring.py +10 -9
- {funboost-44.1.dist-info → funboost-44.3.dist-info}/METADATA +34 -17
- {funboost-44.1.dist-info → funboost-44.3.dist-info}/RECORD +61 -60
- funboost/core/try_get_user_funboost_common_config.py +0 -0
- {funboost-44.1.dist-info → funboost-44.3.dist-info}/LICENSE +0 -0
- {funboost-44.1.dist-info → funboost-44.3.dist-info}/WHEEL +0 -0
- {funboost-44.1.dist-info → funboost-44.3.dist-info}/entry_points.txt +0 -0
- {funboost-44.1.dist-info → funboost-44.3.dist-info}/top_level.txt +0 -0
|
@@ -60,11 +60,9 @@ class RedisPriorityConsumer(RedisConsumerAckAble):
|
|
|
60
60
|
if task_tuple:
|
|
61
61
|
msg = task_tuple[1]
|
|
62
62
|
self.redis_db_frame.zadd(self._unack_zset_name, {msg: time.time()})
|
|
63
|
-
self.logger.debug(task_tuple)
|
|
64
|
-
self._print_message_get_from_broker('redis', msg)
|
|
63
|
+
# self.logger.debug(task_tuple)
|
|
65
64
|
# self.logger.debug(f'从redis的 [{self._queue_name}] 队列中 取出的消息是: {task_str_list} ')
|
|
66
|
-
|
|
67
|
-
kw = {'body': task_dict, 'task_str': msg}
|
|
65
|
+
kw = {'body': msg, 'task_str': msg}
|
|
68
66
|
self._submit_task(kw)
|
|
69
67
|
|
|
70
68
|
def _shedual_task(self):
|
|
@@ -87,10 +85,8 @@ class RedisPriorityConsumer(RedisConsumerAckAble):
|
|
|
87
85
|
except redis5.WatchError:
|
|
88
86
|
continue
|
|
89
87
|
if task_tuple:
|
|
90
|
-
self._print_message_get_from_broker('redis', msg)
|
|
91
88
|
# self.logger.debug(f'从redis的 [{self._queue_name}] 队列中 取出的消息是: {task_str_list} ')
|
|
92
|
-
|
|
93
|
-
kw = {'body': task_dict, 'task_str': msg}
|
|
89
|
+
kw = {'body': msg, 'task_str': msg}
|
|
94
90
|
self._submit_task(kw)
|
|
95
91
|
|
|
96
92
|
def _requeue(self, kw):
|
|
@@ -17,9 +17,8 @@ class RedisConsumer(AbstractConsumer, RedisMixin):
|
|
|
17
17
|
while True:
|
|
18
18
|
result = self.redis_db_frame.blpop(self._queue_name,timeout=60)
|
|
19
19
|
if result:
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
kw = {'body': task_dict}
|
|
20
|
+
|
|
21
|
+
kw = {'body': result[1]}
|
|
23
22
|
self._submit_task(kw)
|
|
24
23
|
|
|
25
24
|
def _confirm_consume(self, kw):
|
|
@@ -18,8 +18,8 @@ class RedisPbSubConsumer(AbstractConsumer, RedisMixin):
|
|
|
18
18
|
pub.subscribe(self.queue_name)
|
|
19
19
|
for item in pub.listen():
|
|
20
20
|
if item['type'] == 'message':
|
|
21
|
-
|
|
22
|
-
kw = {'body':
|
|
21
|
+
|
|
22
|
+
kw = {'body': item['data']}
|
|
23
23
|
self._submit_task(kw)
|
|
24
24
|
|
|
25
25
|
def _shedual_task(self):
|
|
@@ -29,7 +29,7 @@ class RedisPbSubConsumer(AbstractConsumer, RedisMixin):
|
|
|
29
29
|
while True: # 无限循环
|
|
30
30
|
msg_list = pub.parse_response(timeout=60) # 得到消息内容
|
|
31
31
|
if msg_list:
|
|
32
|
-
kw = {'body':
|
|
32
|
+
kw = {'body': msg_list[2]}
|
|
33
33
|
self._submit_task(kw)
|
|
34
34
|
|
|
35
35
|
|
|
@@ -44,10 +44,10 @@ class RedisStreamConsumer(AbstractConsumer, RedisMixin):
|
|
|
44
44
|
{self.queue_name: ">"}, count=100, block=60 * 1000)
|
|
45
45
|
if results:
|
|
46
46
|
# self.logger.debug(f'从redis的 [{self._queue_name}] stream 中 取出的消息是: {results} ')
|
|
47
|
-
self._print_message_get_from_broker(
|
|
47
|
+
self._print_message_get_from_broker( results)
|
|
48
48
|
# print(results[0][1])
|
|
49
49
|
for msg_id, msg in results[0][1]:
|
|
50
|
-
kw = {'body':
|
|
50
|
+
kw = {'body': msg[''], 'msg_id': msg_id}
|
|
51
51
|
self._submit_task(kw)
|
|
52
52
|
|
|
53
53
|
def _confirm_consume(self, kw):
|
|
@@ -91,5 +91,5 @@ class RedisStreamConsumer(AbstractConsumer, RedisMixin):
|
|
|
91
91
|
self.logger.warning(f' {self._queue_name} 的分组 {self.group} 的消费者 {self.consumer_identification} 夺取 断开的消费者 {xinfo_item["name"]}'
|
|
92
92
|
f' {len(xclaim_task_list)} 个任务,详细是 {xclaim_task_list} ')
|
|
93
93
|
for task in xclaim_task_list:
|
|
94
|
-
kw = {'body':
|
|
94
|
+
kw = {'body': task[1][''], 'msg_id': task[0]}
|
|
95
95
|
self._submit_task(kw)
|
|
@@ -31,8 +31,8 @@ class RocketmqConsumer(AbstractConsumer):
|
|
|
31
31
|
|
|
32
32
|
def callback(rocketmq_msg):
|
|
33
33
|
# self.logger.debug(f'从rocketmq的 [{self._queue_name}] 主题的queue_id {rocketmq_msg.queue_id} 中 取出的消息是:{rocketmq_msg.body}')
|
|
34
|
-
|
|
35
|
-
kw = {'body':
|
|
34
|
+
|
|
35
|
+
kw = {'body': rocketmq_msg.body, 'rocketmq_msg': rocketmq_msg}
|
|
36
36
|
self._submit_task(kw)
|
|
37
37
|
|
|
38
38
|
consumer.subscribe(self._queue_name, callback)
|
|
@@ -20,7 +20,7 @@ class SqlachemyConsumer(AbstractConsumer):
|
|
|
20
20
|
sqla_task_dict = self.queue.get()
|
|
21
21
|
# self.logger.debug(f'从数据库 {frame_config.SQLACHEMY_ENGINE_URL[:25]}。。 的 [{self._queue_name}] 队列中 取出的消息是: 消息是: {sqla_task_dict}')
|
|
22
22
|
self._print_message_get_from_broker(f'从数据库 {BrokerConnConfig.SQLACHEMY_ENGINE_URL[:25]}', sqla_task_dict)
|
|
23
|
-
kw = {'body':
|
|
23
|
+
kw = {'body': sqla_task_dict['body'], 'sqla_task_dict': sqla_task_dict}
|
|
24
24
|
self._submit_task(kw)
|
|
25
25
|
|
|
26
26
|
def _confirm_consume(self, kw):
|
|
@@ -42,10 +42,10 @@ class TCPConsumer(AbstractConsumer, ):
|
|
|
42
42
|
# print('server收到的数据', data)
|
|
43
43
|
if not data:
|
|
44
44
|
break
|
|
45
|
-
self._print_message_get_from_broker(f'udp {self._ip_port_raw}', data.decode())
|
|
45
|
+
# self._print_message_get_from_broker(f'udp {self._ip_port_raw}', data.decode())
|
|
46
46
|
tcp_cli_sock.send('has_recived'.encode())
|
|
47
47
|
# tcp_cli_sock.close()
|
|
48
|
-
kw = {'body':
|
|
48
|
+
kw = {'body': data}
|
|
49
49
|
self._submit_task(kw)
|
|
50
50
|
tcp_cli_sock.close()
|
|
51
51
|
except ConnectionResetError:
|
|
@@ -22,8 +22,8 @@ class TxtFileConsumer(AbstractConsumer, ):
|
|
|
22
22
|
while True:
|
|
23
23
|
with file_lock:
|
|
24
24
|
item = queue.get()
|
|
25
|
-
|
|
26
|
-
kw = {'body':
|
|
25
|
+
|
|
26
|
+
kw = {'body': item, 'q': queue, 'item': item}
|
|
27
27
|
self._submit_task(kw)
|
|
28
28
|
|
|
29
29
|
def _confirm_consume(self, kw):
|
|
@@ -31,9 +31,9 @@ class UDPConsumer(AbstractConsumer, ):
|
|
|
31
31
|
while True:
|
|
32
32
|
data, client_addr = server.recvfrom(self.BUFSIZE)
|
|
33
33
|
# print('server收到的数据', data)
|
|
34
|
-
self._print_message_get_from_broker(f'udp {ip_port}', data.decode())
|
|
34
|
+
# self._print_message_get_from_broker(f'udp {ip_port}', data.decode())
|
|
35
35
|
server.sendto('has_recived'.encode(), client_addr)
|
|
36
|
-
kw = {'body':
|
|
36
|
+
kw = {'body': data}
|
|
37
37
|
self._submit_task(kw)
|
|
38
38
|
|
|
39
39
|
def _confirm_consume(self, kw):
|
|
@@ -4,10 +4,11 @@ import os
|
|
|
4
4
|
import socket
|
|
5
5
|
import json
|
|
6
6
|
# import time
|
|
7
|
-
import zmq
|
|
7
|
+
# import zmq
|
|
8
8
|
import multiprocessing
|
|
9
9
|
from funboost.constant import BrokerEnum
|
|
10
10
|
from funboost.consumers.base_consumer import AbstractConsumer
|
|
11
|
+
from funboost.core.lazy_impoter import ZmqImporter
|
|
11
12
|
# from nb_log import get_logger
|
|
12
13
|
from funboost.core.loggers import get_funboost_file_logger
|
|
13
14
|
|
|
@@ -32,17 +33,17 @@ logger_zeromq_broker = get_funboost_file_logger('zeromq_broker')
|
|
|
32
33
|
# noinspection PyUnresolvedReferences
|
|
33
34
|
def start_broker(port_router: int, port_dealer: int):
|
|
34
35
|
try:
|
|
35
|
-
context = zmq.Context()
|
|
36
|
+
context = ZmqImporter().zmq.Context()
|
|
36
37
|
# noinspection PyUnresolvedReferences
|
|
37
|
-
frontend = context.socket(zmq.ROUTER)
|
|
38
|
-
backend = context.socket(zmq.DEALER)
|
|
38
|
+
frontend = context.socket(ZmqImporter().zmq.ROUTER)
|
|
39
|
+
backend = context.socket(ZmqImporter().zmq.DEALER)
|
|
39
40
|
frontend.bind(f"tcp://*:{port_router}")
|
|
40
41
|
backend.bind(f"tcp://*:{port_dealer}")
|
|
41
42
|
|
|
42
43
|
# Initialize poll set
|
|
43
|
-
poller = zmq.Poller()
|
|
44
|
-
poller.register(frontend, zmq.POLLIN)
|
|
45
|
-
poller.register(backend, zmq.POLLIN)
|
|
44
|
+
poller = ZmqImporter().zmq.Poller()
|
|
45
|
+
poller.register(frontend, ZmqImporter().zmq.POLLIN)
|
|
46
|
+
poller.register(backend, ZmqImporter().zmq.POLLIN)
|
|
46
47
|
logger_zeromq_broker.info(f'broker 绑定端口 {port_router} {port_dealer} 成功')
|
|
47
48
|
|
|
48
49
|
# Switch messages between sockets
|
|
@@ -50,11 +51,11 @@ def start_broker(port_router: int, port_dealer: int):
|
|
|
50
51
|
while True:
|
|
51
52
|
socks = dict(poller.poll()) # 轮询器 循环接收
|
|
52
53
|
|
|
53
|
-
if socks.get(frontend) == zmq.POLLIN:
|
|
54
|
+
if socks.get(frontend) == ZmqImporter().zmq.POLLIN:
|
|
54
55
|
message = frontend.recv_multipart()
|
|
55
56
|
backend.send_multipart(message)
|
|
56
57
|
|
|
57
|
-
if socks.get(backend) == zmq.POLLIN:
|
|
58
|
+
if socks.get(backend) == ZmqImporter().zmq.POLLIN:
|
|
58
59
|
message = backend.recv_multipart()
|
|
59
60
|
frontend.send_multipart(message)
|
|
60
61
|
except BaseException as e:
|
|
@@ -87,16 +88,15 @@ class ZeroMqConsumer(AbstractConsumer):
|
|
|
87
88
|
# noinspection DuplicatedCode
|
|
88
89
|
def _shedual_task(self):
|
|
89
90
|
self.start_broker_queue_name_as_port()
|
|
90
|
-
context = zmq.Context()
|
|
91
|
+
context = ZmqImporter().zmq.Context()
|
|
91
92
|
# noinspection PyUnresolvedReferences
|
|
92
|
-
zsocket = context.socket(zmq.REP)
|
|
93
|
+
zsocket = context.socket(ZmqImporter().zmq.REP)
|
|
93
94
|
zsocket.connect(f"tcp://localhost:{int(self._queue_name) + 1}")
|
|
94
95
|
|
|
95
96
|
while True:
|
|
96
97
|
message = zsocket.recv()
|
|
97
98
|
# self.logger.debug(f""" 从 zeromq 取出的消息是 {message}""")
|
|
98
|
-
self.
|
|
99
|
-
self._submit_task({'body': json.loads(message)})
|
|
99
|
+
self._submit_task({'body': message})
|
|
100
100
|
zsocket.send('recv ok'.encode())
|
|
101
101
|
|
|
102
102
|
def _confirm_consume(self, kw):
|
|
@@ -7,7 +7,7 @@ import importlib.util
|
|
|
7
7
|
# import nb_log
|
|
8
8
|
from funboost.core.loggers import FunboostFileLoggerMixin
|
|
9
9
|
from funboost.utils.decorators import flyweight
|
|
10
|
-
from funboost.core.lazy_impoter import
|
|
10
|
+
from funboost.core.lazy_impoter import funboost_lazy_impoter
|
|
11
11
|
|
|
12
12
|
@flyweight
|
|
13
13
|
class BoosterDiscovery(FunboostFileLoggerMixin):
|
|
@@ -68,7 +68,7 @@ class BoosterDiscovery(FunboostFileLoggerMixin):
|
|
|
68
68
|
spec = importlib.util.spec_from_file_location(module_name, file_path)
|
|
69
69
|
module = importlib.util.module_from_spec(spec)
|
|
70
70
|
spec.loader.exec_module(module)
|
|
71
|
-
|
|
71
|
+
funboost_lazy_impoter.BoostersManager.show_all_boosters()
|
|
72
72
|
|
|
73
73
|
|
|
74
74
|
if __name__ == '__main__':
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
def _try_get_user_funboost_common_config(funboost_common_conf_field:str):
|
|
2
|
+
try:
|
|
3
|
+
import funboost_config # 第一次启动funboost前还没这个文件,或者还没有初始化配置之前,就要使用使用配置.
|
|
4
|
+
return getattr(funboost_config.FunboostCommonConfig,funboost_common_conf_field)
|
|
5
|
+
except Exception as e:
|
|
6
|
+
print(e)
|
|
7
|
+
return None
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import pytz
|
|
2
|
+
import time
|
|
3
|
+
|
|
4
|
+
import datetime
|
|
5
|
+
|
|
6
|
+
import typing
|
|
7
|
+
|
|
8
|
+
from nb_time import NbTime
|
|
9
|
+
from funboost.funboost_config_deafult import FunboostCommonConfig
|
|
10
|
+
|
|
11
|
+
class FunboostTime(NbTime):
|
|
12
|
+
default_formatter = NbTime.FORMATTER_DATETIME_NO_ZONE
|
|
13
|
+
def get_time_zone_str(self,time_zone: typing.Union[str, datetime.tzinfo,None] = None):
|
|
14
|
+
return time_zone or self.default_time_zone or FunboostCommonConfig.TIMEZONE or self.get_localzone_name()
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
if __name__ == '__main__':
|
|
19
|
+
print(NbTime())
|
|
20
|
+
for i in range(100000):
|
|
21
|
+
# print(generate_publish_time())
|
|
22
|
+
# print(generate_publish_time_format())
|
|
23
|
+
# generate_publish_time()
|
|
24
|
+
# generate_publish_time_format()
|
|
25
|
+
|
|
26
|
+
datetime.datetime.now(tz=pytz.timezone(FunboostCommonConfig.TIMEZONE)).strftime(NbTime.FORMATTER_DATETIME_NO_ZONE)
|
|
27
|
+
datetime.datetime.now(tz=pytz.timezone(FunboostCommonConfig.TIMEZONE)).timestamp()
|
|
28
|
+
print(NbTime())
|
funboost/core/helper_funs.py
CHANGED
|
@@ -2,6 +2,8 @@ import copy
|
|
|
2
2
|
import time
|
|
3
3
|
import uuid
|
|
4
4
|
|
|
5
|
+
from funboost.core.funboost_time import FunboostTime
|
|
6
|
+
|
|
5
7
|
|
|
6
8
|
def get_publish_time(paramsx: dict):
|
|
7
9
|
"""
|
|
@@ -37,13 +39,23 @@ def block_python_main_thread_exit():
|
|
|
37
39
|
run_forever = block_python_main_thread_exit
|
|
38
40
|
|
|
39
41
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
return
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
42
|
+
class MsgGenerater:
|
|
43
|
+
@staticmethod
|
|
44
|
+
def generate_task_id(queue_name:str) -> str:
|
|
45
|
+
return f'{queue_name}_result:{uuid.uuid4()}'
|
|
46
|
+
|
|
47
|
+
@staticmethod
|
|
48
|
+
def generate_publish_time() -> float:
|
|
49
|
+
return round(FunboostTime().timestamp,4)
|
|
50
|
+
|
|
51
|
+
@staticmethod
|
|
52
|
+
def generate_publish_time_format() -> str:
|
|
53
|
+
return FunboostTime().get_str()
|
|
54
|
+
|
|
55
|
+
@classmethod
|
|
56
|
+
def generate_pulish_time_and_task_id(cls,queue_name:str,task_id=None):
|
|
57
|
+
extra_params = {'task_id': task_id or cls.generate_task_id(queue_name), 'publish_time': cls.generate_publish_time(),
|
|
58
|
+
'publish_time_format': cls.generate_publish_time_format()}
|
|
59
|
+
return extra_params
|
|
60
|
+
|
|
47
61
|
|
|
48
|
-
def generate_task_id(queue_name:str):
|
|
49
|
-
return f'{queue_name}_result:{uuid.uuid4()}'
|
funboost/core/lazy_impoter.py
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import abc
|
|
2
2
|
|
|
3
|
-
from funboost.utils.decorators import cached_method_result, singleton, SingletonBaseNew, SingletonBaseCustomInit
|
|
3
|
+
from funboost.utils.decorators import cached_method_result, singleton, SingletonBaseNew, SingletonBaseCustomInit, singleton_no_lock
|
|
4
4
|
|
|
5
|
+
"""
|
|
6
|
+
延迟导入
|
|
7
|
+
或者使用时候再pip安装
|
|
8
|
+
"""
|
|
5
9
|
|
|
6
|
-
# @singleton # 不方便代码补全
|
|
7
10
|
|
|
8
|
-
class
|
|
11
|
+
class FunboostLazyImpoter(SingletonBaseNew):
|
|
9
12
|
"""
|
|
10
13
|
延迟导入,避免需要互相导入.
|
|
11
14
|
"""
|
|
@@ -23,7 +26,7 @@ class LazyImpoter(SingletonBaseNew):
|
|
|
23
26
|
# return get_current_taskid
|
|
24
27
|
|
|
25
28
|
|
|
26
|
-
|
|
29
|
+
funboost_lazy_impoter = FunboostLazyImpoter()
|
|
27
30
|
|
|
28
31
|
|
|
29
32
|
# noinspection SpellCheckingInspection
|
|
@@ -37,34 +40,19 @@ class GeventImporter:
|
|
|
37
40
|
from gevent.queue import JoinableQueue
|
|
38
41
|
"""
|
|
39
42
|
|
|
40
|
-
|
|
41
|
-
@cached_method_result
|
|
42
|
-
def gevent(self):
|
|
43
|
+
def __init__(self):
|
|
43
44
|
import gevent
|
|
44
45
|
print('导入gevent')
|
|
45
|
-
return gevent
|
|
46
|
-
|
|
47
|
-
@property
|
|
48
|
-
@cached_method_result
|
|
49
|
-
def gevent_pool(self):
|
|
50
46
|
from gevent import pool as gevent_pool
|
|
51
|
-
return gevent_pool
|
|
52
|
-
|
|
53
|
-
@property
|
|
54
|
-
@cached_method_result
|
|
55
|
-
def monkey(self):
|
|
56
47
|
from gevent import monkey
|
|
57
|
-
print('导入gevent')
|
|
58
|
-
return monkey
|
|
59
|
-
|
|
60
|
-
@property
|
|
61
|
-
@cached_method_result
|
|
62
|
-
def JoinableQueue(self):
|
|
63
48
|
from gevent.queue import JoinableQueue
|
|
64
|
-
|
|
49
|
+
self.gevent = gevent
|
|
50
|
+
self.gevent_pool = gevent_pool
|
|
51
|
+
self.monkey = monkey
|
|
52
|
+
self.JoinableQueue = JoinableQueue
|
|
65
53
|
|
|
66
54
|
|
|
67
|
-
@
|
|
55
|
+
@singleton_no_lock
|
|
68
56
|
class EventletImporter:
|
|
69
57
|
"""
|
|
70
58
|
避免提前导入
|
|
@@ -79,23 +67,110 @@ class EventletImporter:
|
|
|
79
67
|
self.patcher = patcher
|
|
80
68
|
self.Timeout = Timeout
|
|
81
69
|
|
|
82
|
-
|
|
70
|
+
|
|
71
|
+
@singleton_no_lock
|
|
83
72
|
class PeeweeImporter:
|
|
84
73
|
def __init__(self):
|
|
85
|
-
|
|
74
|
+
"""pip install peewee == 3.17"""
|
|
86
75
|
from peewee import ModelSelect, Model, BigAutoField, CharField, DateTimeField, MySQLDatabase
|
|
87
76
|
from playhouse.shortcuts import model_to_dict, dict_to_model
|
|
88
77
|
self.ModelSelect = ModelSelect
|
|
89
78
|
self.Model = Model
|
|
90
79
|
self.BigAutoField = BigAutoField
|
|
91
80
|
self.CharField = CharField
|
|
92
|
-
self.DateTimeField =DateTimeField
|
|
81
|
+
self.DateTimeField = DateTimeField
|
|
93
82
|
self.MySQLDatabase = MySQLDatabase
|
|
94
83
|
self.model_to_dict = model_to_dict
|
|
95
|
-
self.dict_to_model =dict_to_model
|
|
84
|
+
self.dict_to_model = dict_to_model
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
@singleton_no_lock
|
|
88
|
+
class AioHttpImporter:
|
|
89
|
+
|
|
90
|
+
def __init__(self):
|
|
91
|
+
"""pip install aiohttp==3.8.3"""
|
|
92
|
+
from aiohttp import web
|
|
93
|
+
from aiohttp.web_request import Request
|
|
94
|
+
self.web = web
|
|
95
|
+
self.Request = Request
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
@singleton_no_lock
|
|
99
|
+
class NatsImporter:
|
|
100
|
+
def __init__(self):
|
|
101
|
+
"""pip install nats-python """
|
|
102
|
+
from pynats import NATSClient, NATSMessage
|
|
103
|
+
self.NATSClient = NATSClient
|
|
104
|
+
self.NATSMessage = NATSMessage
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
@singleton_no_lock
|
|
108
|
+
class GnsqImporter:
|
|
109
|
+
def __init__(self):
|
|
110
|
+
"""pip install gnsq==1.0.1"""
|
|
111
|
+
from gnsq import Consumer, Message
|
|
112
|
+
from gnsq import Producer, NsqdHTTPClient
|
|
113
|
+
from gnsq.errors import NSQHttpError
|
|
114
|
+
self.Consumer = Consumer
|
|
115
|
+
self.Message = Message
|
|
116
|
+
self.Producer = Producer
|
|
117
|
+
self.NsqdHTTPClient = NsqdHTTPClient
|
|
118
|
+
self.NSQHttpError = NSQHttpError
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
@singleton_no_lock
|
|
122
|
+
class ElasticsearchImporter:
|
|
123
|
+
def __init__(self):
|
|
124
|
+
"""pip install elasticsearch """
|
|
125
|
+
from elasticsearch import helpers
|
|
126
|
+
self.helpers = helpers
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
@singleton_no_lock
|
|
130
|
+
class PsutilImporter:
|
|
131
|
+
def __init__(self):
|
|
132
|
+
"""pip install psutil"""
|
|
133
|
+
import psutil
|
|
134
|
+
self.psutil = psutil
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
@singleton_no_lock
|
|
138
|
+
class PahoMqttImporter:
|
|
139
|
+
def __init__(self):
|
|
140
|
+
"""pip install paho-mqtt"""
|
|
141
|
+
import paho.mqtt.client as mqtt
|
|
142
|
+
self.mqtt = mqtt
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
@singleton_no_lock
|
|
146
|
+
class ZmqImporter:
|
|
147
|
+
def __init__(self):
|
|
148
|
+
"""pip install zmq pyzmq"""
|
|
149
|
+
import zmq
|
|
150
|
+
self.zmq = zmq
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
@singleton_no_lock
|
|
154
|
+
class KafkaPythonImporter:
|
|
155
|
+
def __init__(self):
|
|
156
|
+
"""pip install kafka-python==2.0.2"""
|
|
157
|
+
|
|
158
|
+
from kafka import KafkaConsumer as OfficialKafkaConsumer, KafkaProducer, KafkaAdminClient
|
|
159
|
+
from kafka.admin import NewTopic
|
|
160
|
+
from kafka.errors import TopicAlreadyExistsError
|
|
161
|
+
|
|
162
|
+
self.OfficialKafkaConsumer = OfficialKafkaConsumer
|
|
163
|
+
self.KafkaProducer = KafkaProducer
|
|
164
|
+
self.KafkaAdminClient = KafkaAdminClient
|
|
165
|
+
self.NewTopic = NewTopic
|
|
166
|
+
self.TopicAlreadyExistsError = TopicAlreadyExistsError
|
|
167
|
+
|
|
96
168
|
|
|
97
169
|
if __name__ == '__main__':
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
170
|
+
print()
|
|
171
|
+
for i in range(10000000):
|
|
172
|
+
# funboost_lazy_impoter.BoostersManager
|
|
173
|
+
# EventletImporter().greenpool
|
|
174
|
+
# GeventImporter().JoinableQueue
|
|
175
|
+
ZmqImporter().zmq
|
|
176
|
+
print()
|
funboost/core/loggers.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import nb_log
|
|
2
|
-
from funboost.core.
|
|
2
|
+
from funboost.core.funboost_config_getter import _try_get_user_funboost_common_config
|
|
3
3
|
|
|
4
4
|
# noinspection PyUnresolvedReferences
|
|
5
5
|
from nb_log import get_logger, LoggerLevelSetterMixin, nb_log_config_default
|
|
@@ -7,11 +7,11 @@ from concurrent.futures import ProcessPoolExecutor
|
|
|
7
7
|
from funboost.core.booster import Booster
|
|
8
8
|
from funboost.core.helper_funs import run_forever
|
|
9
9
|
from funboost.core.loggers import flogger
|
|
10
|
-
from funboost.core.lazy_impoter import
|
|
10
|
+
from funboost.core.lazy_impoter import funboost_lazy_impoter
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
def _run_consumer_in_new_process(queue_name, ):
|
|
14
|
-
booster_current_pid =
|
|
14
|
+
booster_current_pid = funboost_lazy_impoter.BoostersManager.get_or_create_booster_by_queue_name(queue_name)
|
|
15
15
|
# booster_current_pid = boost(**boost_params)(consuming_function)
|
|
16
16
|
booster_current_pid.consume()
|
|
17
17
|
# ConsumersManager.join_all_consumer_shedual_task_thread()
|
|
@@ -49,7 +49,7 @@ def run_consumer_with_multi_process(booster: Booster, process_num=1):
|
|
|
49
49
|
|
|
50
50
|
|
|
51
51
|
def _multi_process_pub_params_list_in_new_process(queue_name, msgs: List[dict]):
|
|
52
|
-
booster_current_pid =
|
|
52
|
+
booster_current_pid = funboost_lazy_impoter.BoostersManager.get_or_create_booster_by_queue_name(queue_name)
|
|
53
53
|
publisher = booster_current_pid.publisher
|
|
54
54
|
publisher.set_log_level(20) # 超高速发布,如果打印详细debug日志会卡死屏幕和严重降低代码速度。
|
|
55
55
|
for msg in msgs:
|
|
@@ -5,6 +5,9 @@
|
|
|
5
5
|
import datetime
|
|
6
6
|
import json
|
|
7
7
|
|
|
8
|
+
"""
|
|
9
|
+
pip install Flask flask_bootstrap flask_wtf wtforms flask_login
|
|
10
|
+
"""
|
|
8
11
|
from flask import render_template, Flask, request, url_for, jsonify, flash, redirect
|
|
9
12
|
from flask_bootstrap import Bootstrap
|
|
10
13
|
from flask_wtf import FlaskForm
|
|
@@ -9,17 +9,15 @@ import json
|
|
|
9
9
|
import logging
|
|
10
10
|
import multiprocessing
|
|
11
11
|
import threading
|
|
12
|
-
import uuid
|
|
13
12
|
import time
|
|
14
13
|
import typing
|
|
15
14
|
from functools import wraps
|
|
16
15
|
from threading import Lock
|
|
17
|
-
import datetime
|
|
18
16
|
import amqpstorm
|
|
19
17
|
|
|
20
18
|
import nb_log
|
|
21
19
|
from funboost.core.func_params_model import PublisherParams, PriorityConsumingControlConfig
|
|
22
|
-
from funboost.core.helper_funs import
|
|
20
|
+
from funboost.core.helper_funs import MsgGenerater
|
|
23
21
|
from funboost.core.loggers import develop_logger
|
|
24
22
|
|
|
25
23
|
from pikav1.exceptions import AMQPError as PikaAMQPError
|
|
@@ -28,7 +26,7 @@ from pikav1.exceptions import AMQPError as PikaAMQPError
|
|
|
28
26
|
from funboost.core.loggers import LoggerLevelSetterMixin, FunboostFileLoggerMixin, get_logger
|
|
29
27
|
from funboost.core.msg_result_getter import AsyncResult, AioAsyncResult
|
|
30
28
|
from funboost.core.task_id_logger import TaskIdLogger
|
|
31
|
-
from funboost.utils import decorators
|
|
29
|
+
from funboost.utils import decorators
|
|
32
30
|
from funboost.funboost_config_deafult import BrokerConnConfig, FunboostCommonConfig
|
|
33
31
|
|
|
34
32
|
RedisAsyncResult = AsyncResult # 别名
|
|
@@ -191,9 +189,8 @@ class AbstractPublisher(LoggerLevelSetterMixin, metaclass=abc.ABCMeta, ):
|
|
|
191
189
|
raw_extra = msg['extra']
|
|
192
190
|
if self.publish_params_checker and self.publisher_params.should_check_publish_func_params:
|
|
193
191
|
self.publish_params_checker.check_params(msg_function_kw)
|
|
194
|
-
task_id = task_id or generate_task_id(self._queue_name)
|
|
195
|
-
extra_params =
|
|
196
|
-
'publish_time_format': time.strftime('%Y-%m-%d %H:%M:%S')}
|
|
192
|
+
task_id = task_id or MsgGenerater.generate_task_id(self._queue_name)
|
|
193
|
+
extra_params = MsgGenerater.generate_pulish_time_and_task_id(self._queue_name, task_id=task_id)
|
|
197
194
|
if priority_control_config:
|
|
198
195
|
extra_params.update(priority_control_config.dict(exclude_none=True))
|
|
199
196
|
extra_params.update(raw_extra)
|
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
import os
|
|
6
6
|
|
|
7
|
+
from funboost.core.lazy_impoter import KafkaPythonImporter
|
|
8
|
+
|
|
7
9
|
if os.name == 'nt':
|
|
8
10
|
"""
|
|
9
11
|
为了保险起见,这样做一下,设置一下path,否则anaconda安装的python可能出现 ImportError: DLL load failed while importing cimpl: 找不到指定的模块。
|
|
@@ -24,12 +26,7 @@ if os.name == 'nt':
|
|
|
24
26
|
|
|
25
27
|
import atexit
|
|
26
28
|
import time
|
|
27
|
-
|
|
28
|
-
from kafka import KafkaProducer, KafkaAdminClient
|
|
29
|
-
# noinspection PyPackageRequirements
|
|
30
|
-
from kafka.admin import NewTopic
|
|
31
|
-
# noinspection PyPackageRequirements
|
|
32
|
-
from kafka.errors import TopicAlreadyExistsError
|
|
29
|
+
|
|
33
30
|
from confluent_kafka import Producer as ConfluentProducer
|
|
34
31
|
from funboost.funboost_config_deafult import BrokerConnConfig
|
|
35
32
|
from funboost.publishers.base_publisher import AbstractPublisher
|
|
@@ -45,10 +42,10 @@ class ConfluentKafkaPublisher(AbstractPublisher, ):
|
|
|
45
42
|
|
|
46
43
|
# self._producer = KafkaProducer(bootstrap_servers=funboost_config_deafult.KAFKA_BOOTSTRAP_SERVERS)
|
|
47
44
|
try:
|
|
48
|
-
admin_client = KafkaAdminClient(bootstrap_servers=BrokerConnConfig.KAFKA_BOOTSTRAP_SERVERS)
|
|
49
|
-
admin_client.create_topics([NewTopic(self._queue_name, 10, 1)])
|
|
45
|
+
admin_client = KafkaPythonImporter().KafkaAdminClient(bootstrap_servers=BrokerConnConfig.KAFKA_BOOTSTRAP_SERVERS)
|
|
46
|
+
admin_client.create_topics([KafkaPythonImporter().NewTopic(self._queue_name, 10, 1)])
|
|
50
47
|
# admin_client.create_partitions({self._queue_name: NewPartitions(total_count=16)})
|
|
51
|
-
except TopicAlreadyExistsError:
|
|
48
|
+
except KafkaPythonImporter().TopicAlreadyExistsError:
|
|
52
49
|
pass
|
|
53
50
|
except BaseException as e:
|
|
54
51
|
self.logger.exception(e)
|
|
@@ -92,10 +89,10 @@ class SaslPlainKafkaPublisher(ConfluentKafkaPublisher):
|
|
|
92
89
|
def custom_init(self):
|
|
93
90
|
# self._producer = KafkaProducer(bootstrap_servers=funboost_config_deafult.KAFKA_BOOTSTRAP_SERVERS)
|
|
94
91
|
try:
|
|
95
|
-
admin_client = KafkaAdminClient(**BrokerConnConfig.KFFKA_SASL_CONFIG)
|
|
96
|
-
admin_client.create_topics([NewTopic(self._queue_name, 10, 1)])
|
|
92
|
+
admin_client = KafkaPythonImporter().KafkaAdminClient(**BrokerConnConfig.KFFKA_SASL_CONFIG)
|
|
93
|
+
admin_client.create_topics([KafkaPythonImporter().NewTopic(self._queue_name, 10, 1)])
|
|
97
94
|
# admin_client.create_partitions({self._queue_name: NewPartitions(total_count=16)})
|
|
98
|
-
except TopicAlreadyExistsError:
|
|
95
|
+
except KafkaPythonImporter().TopicAlreadyExistsError:
|
|
99
96
|
pass
|
|
100
97
|
except BaseException as e:
|
|
101
98
|
self.logger.exception(e)
|