funboost 49.6__py3-none-any.whl → 49.7__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.

Files changed (30) hide show
  1. funboost/__init__.py +1 -1
  2. funboost/constant.py +19 -0
  3. funboost/consumers/base_consumer.py +27 -7
  4. funboost/consumers/faststream_consumer.py +1 -1
  5. funboost/consumers/http_consumer.py +12 -7
  6. funboost/consumers/kafka_consumer_manually_commit.py +0 -2
  7. funboost/consumers/tcp_consumer.py +11 -10
  8. funboost/consumers/udp_consumer.py +9 -6
  9. funboost/consumers/zeromq_consumer.py +18 -11
  10. funboost/core/exceptions.py +7 -0
  11. funboost/core/func_params_model.py +16 -7
  12. funboost/core/function_result_status_saver.py +15 -0
  13. funboost/core/msg_result_getter.py +51 -1
  14. funboost/core/serialization.py +28 -1
  15. funboost/factories/consumer_factory.py +1 -1
  16. funboost/factories/publisher_factotry.py +1 -1
  17. funboost/funboost_config_deafult.py +2 -2
  18. funboost/function_result_web/__pycache__/app.cpython-39.pyc +0 -0
  19. funboost/publishers/base_publisher.py +16 -2
  20. funboost/publishers/http_publisher.py +7 -1
  21. funboost/publishers/tcp_publisher.py +10 -8
  22. funboost/publishers/udp_publisher.py +8 -6
  23. funboost/publishers/zeromq_publisher.py +5 -1
  24. funboost/timing_job/timing_push.py +3 -1
  25. {funboost-49.6.dist-info → funboost-49.7.dist-info}/METADATA +165 -171
  26. {funboost-49.6.dist-info → funboost-49.7.dist-info}/RECORD +30 -30
  27. {funboost-49.6.dist-info → funboost-49.7.dist-info}/WHEEL +1 -1
  28. {funboost-49.6.dist-info → funboost-49.7.dist-info}/LICENSE +0 -0
  29. {funboost-49.6.dist-info → funboost-49.7.dist-info}/entry_points.txt +0 -0
  30. {funboost-49.6.dist-info → funboost-49.7.dist-info}/top_level.txt +0 -0
@@ -10,6 +10,7 @@ import atexit
10
10
  import json
11
11
  import logging
12
12
  import multiprocessing
13
+ from re import S
13
14
  import sys
14
15
  import threading
15
16
  import time
@@ -26,7 +27,7 @@ from funboost.core.loggers import develop_logger
26
27
  # from nb_log import LoggerLevelSetterMixin, LoggerMixin
27
28
  from funboost.core.loggers import LoggerLevelSetterMixin, FunboostFileLoggerMixin, get_logger
28
29
  from funboost.core.msg_result_getter import AsyncResult, AioAsyncResult
29
- from funboost.core.serialization import Serialization
30
+ from funboost.core.serialization import PickleHelper, Serialization
30
31
  from funboost.core.task_id_logger import TaskIdLogger
31
32
  from funboost.utils import decorators
32
33
  from funboost.funboost_config_deafult import BrokerConnConfig, FunboostCommonConfig
@@ -212,7 +213,20 @@ class AbstractPublisher(LoggerLevelSetterMixin, metaclass=abc.ABCMeta, ):
212
213
  msg = copy.deepcopy(msg) # 字典是可变对象,不要改变影响用户自身的传参字典. 用户可能继续使用这个传参字典.
213
214
  msg, msg_function_kw, extra_params, task_id = self._convert_msg(msg, task_id, priority_control_config)
214
215
  t_start = time.time()
215
- msg_json = Serialization.to_json_str(msg)
216
+
217
+ can_not_json_serializable_keys = Serialization.find_can_not_json_serializable_keys(msg)
218
+ if can_not_json_serializable_keys:
219
+ pass
220
+ self.logger.warning(f'msg 中包含不能序列化的键: {can_not_json_serializable_keys}')
221
+ # raise ValueError(f'msg 中包含不能序列化的键: {can_not_json_serializable_keys}')
222
+ new_msg = copy.deepcopy(Serialization.to_dict(msg))
223
+ for key in can_not_json_serializable_keys:
224
+ new_msg[key] = PickleHelper.to_str(new_msg[key])
225
+ new_msg['extra']['can_not_json_serializable_keys'] = can_not_json_serializable_keys
226
+ msg_json = Serialization.to_json_str(new_msg)
227
+ else:
228
+ msg_json = Serialization.to_json_str(msg)
229
+ # print(msg_json)
216
230
  decorators.handle_exception(retry_times=10, is_throw_error=True, time_sleep=0.1)(
217
231
  self.concrete_realization_of_publish)(msg_json)
218
232
 
@@ -14,9 +14,15 @@ class HTTPPublisher(AbstractPublisher, ):
14
14
  # noinspection PyAttributeOutsideInit
15
15
  def custom_init(self):
16
16
  self._http = PoolManager(10)
17
+ self._ip = self.publisher_params.broker_exclusive_config['host']
18
+ self._port = self.publisher_params.broker_exclusive_config['port']
19
+ self._ip_port_str = f'{self._ip}:{self._port}'
20
+ if self._port is None:
21
+ raise ValueError('please specify port')
22
+
17
23
 
18
24
  def concrete_realization_of_publish(self, msg):
19
- url = self.queue_name + '/queue'
25
+ url = self._ip_port_str + '/queue'
20
26
  self._http.request('post', url, fields={'msg': msg})
21
27
 
22
28
  def clear(self):
@@ -10,24 +10,26 @@ class TCPPublisher(AbstractPublisher, ):
10
10
  使用tcp作为中间件,不支持持久化,支持分布式
11
11
  """
12
12
 
13
- BUFSIZE = 10240
14
-
15
13
  # noinspection PyAttributeOutsideInit
16
14
  def custom_init(self):
17
- """ tcp为消息队列中间件 时候 queue_name 要设置为例如 127.0.0.1:5689"""
18
- pass
15
+ self._bufsize = self.publisher_params.broker_exclusive_config['bufsize']
19
16
 
20
17
  # noinspection PyAttributeOutsideInit
21
18
  def concrete_realization_of_publish(self, msg):
22
19
  if not hasattr(self, '_tcp_cli_sock'):
23
- ip__port_str = self.queue_name.split(':')
24
- ip_port = (ip__port_str[0], int(ip__port_str[1]))
20
+ # ip__port_str = self.queue_name.split(':')
21
+ # ip_port = (ip__port_str[0], int(ip__port_str[1]))
22
+ self._ip = self.publisher_params.broker_exclusive_config['host']
23
+ self._port = self.publisher_params.broker_exclusive_config['port']
24
+ self.__ip_port = (self._ip, self._port)
25
+ if self._port is None:
26
+ raise ValueError('please specify port')
25
27
  tcp_cli_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
26
- tcp_cli_sock.connect(ip_port)
28
+ tcp_cli_sock.connect(self.__ip_port)
27
29
  self._tcp_cli_sock = tcp_cli_sock
28
30
 
29
31
  self._tcp_cli_sock.send(msg.encode())
30
- self._tcp_cli_sock.recv(self.BUFSIZE)
32
+ self._tcp_cli_sock.recv(self._bufsize)
31
33
 
32
34
  def clear(self):
33
35
  pass # udp没有保存消息
@@ -10,19 +10,21 @@ class UDPPublisher(AbstractPublisher, ):
10
10
  使用udp作为中间件,不支持持久化,支持分布式
11
11
  """
12
12
 
13
- BUFSIZE = 10240
14
-
15
13
  # noinspection PyAttributeOutsideInit
16
14
  def custom_init(self):
17
- """ udp为消息队列中间件 时候 queue_name 要设置为例如 127.0.0.1:5689"""
15
+ self._bufsize = self.publisher_params.broker_exclusive_config['bufsize']
18
16
  self.__udp_client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
19
- ip__port_str = self.queue_name.split(':')
20
- self.__ip_port = (ip__port_str[0], int(ip__port_str[1]))
17
+ self._ip = self.publisher_params.broker_exclusive_config['host']
18
+ self._port = self.publisher_params.broker_exclusive_config['port']
19
+ self.__ip_port = (self._ip, self._port)
20
+ if self._port is None:
21
+ raise ValueError('please specify port')
21
22
  self.__udp_client.connect(self.__ip_port)
22
23
 
24
+ # noinspection PyAttributeOutsideInit
23
25
  def concrete_realization_of_publish(self, msg):
24
26
  self.__udp_client.send(msg.encode('utf-8'), )
25
- self.__udp_client.recv(self.BUFSIZE)
27
+ self.__udp_client.recv(self._bufsize)
26
28
 
27
29
  def clear(self):
28
30
  pass # udp没有保存消息
@@ -10,9 +10,13 @@ class ZeroMqPublisher(AbstractPublisher):
10
10
  zeromq 中间件的发布者,zeromq基于socket代码,不会持久化,且不需要安装软件。
11
11
  """
12
12
  def custom_init(self):
13
+ self._port = self.publisher_params.broker_exclusive_config['port']
14
+ if self._port is None:
15
+ raise ValueError('please specify port')
16
+
13
17
  context = ZmqImporter().zmq.Context()
14
18
  socket = context.socket(ZmqImporter().zmq.REQ)
15
- socket.connect(f"tcp://localhost:{int(self._queue_name)}")
19
+ socket.connect(f"tcp://localhost:{int(self._port)}")
16
20
  self.socket =socket
17
21
  self.logger.warning('框架使用 zeromq 中间件方式,必须先启动消费者(消费者会顺便启动broker) ,只有启动了服务端才能发布任务')
18
22
 
@@ -146,7 +146,7 @@ if __name__ == '__main__':
146
146
  id='interval_job1'
147
147
  )
148
148
 
149
- # 方式3:使用cron表达式定时执行
149
+ # 方式3:使用cron表达式定时执行,周期运行
150
150
  ApsJobAdder(sum_two_numbers, job_store_kind='redis').add_push_job(
151
151
  trigger='cron',
152
152
  day_of_week='*',
@@ -156,5 +156,7 @@ if __name__ == '__main__':
156
156
  kwargs={"x": 50, "y": 60},
157
157
  replace_existing=True,
158
158
  id='cron_job1')
159
+
160
+
159
161
 
160
162
  ctrl_c_recv() # 启动了守护线程的定时器,一定要阻止主线程退出。 你可以代码最末尾加这个 ctrl_c_recv() 或者加个 while 1:time.sleep(10)