funboost 18.8__py3-none-any.whl → 18.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.

Potentially problematic release.


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

funboost/__init__.py CHANGED
@@ -1,4 +1,4 @@
1
- from funboost.utils import monkey_patches
1
+ from funboost.utils import monkey_patches
2
2
  from funboost.utils import show_funboost_flag
3
3
  import typing
4
4
  # noinspection PyUnresolvedReferences
@@ -19,7 +19,7 @@ from funboost.consumers.base_consumer import (ExceptionForRequeue, ExceptionForR
19
19
  wait_for_possible_has_finish_all_tasks_by_conusmer_list,
20
20
  ActiveCousumerProcessInfoGetter, FunctionResultStatus)
21
21
  from funboost.publishers.base_publisher import (PriorityConsumingControlConfig,
22
- AbstractPublisher, AsyncResult, HasNotAsyncResult)
22
+ AbstractPublisher, AsyncResult, HasNotAsyncResult, AioAsyncResult)
23
23
  from funboost.factories.publisher_factotry import get_publisher
24
24
  from funboost.factories.consumer_factory import get_consumer
25
25
 
@@ -28,12 +28,11 @@ from funboost.utils import nb_print, patch_print, LogManager, get_logger, Logger
28
28
  from funboost.timing_job import fsdf_background_scheduler, timing_publish_deco
29
29
  from funboost.constant import BrokerEnum, ConcurrentModeEnum
30
30
 
31
+
31
32
  # 有的包默认没加handlers,原始的日志不漂亮且不可跳转不知道哪里发生的。这里把warnning级别以上的日志默认加上handlers。
32
33
  # nb_log.get_logger(name='', log_level_int=30, log_filename='pywarning.log')
33
34
 
34
35
 
35
-
36
-
37
36
  class IdeAutoCompleteHelper(LoggerMixin):
38
37
  """
39
38
  为了被装饰的消费函数的敲代码时候的被pycharm自动补全而写的类。
@@ -17,85 +17,13 @@ from kombu.exceptions import KombuError
17
17
  from pikav1.exceptions import AMQPError as PikaAMQPError
18
18
 
19
19
  from nb_log import LoggerLevelSetterMixin, LogManager, LoggerMixin
20
- from funboost.utils import decorators, RedisMixin, time_util
21
- from funboost import funboost_config_deafult
22
- from funboost.concurrent_pool import CustomThreadPoolExecutor
23
-
24
-
25
- class HasNotAsyncResult(Exception):
26
- pass
27
-
28
-
29
- class AsyncResult(RedisMixin):
30
- callback_run_executor = CustomThreadPoolExecutor(200)
31
-
32
- def __init__(self, task_id, timeout=120):
33
- self.task_id = task_id
34
- self.timeout = timeout
35
- self._has_pop = False
36
- self._status_and_result = None
37
-
38
- def set_timeout(self, timeout=60):
39
- self.timeout = timeout
40
- return self
41
-
42
- def is_pending(self):
43
- return not self.redis_db_filter_and_rpc_result.exists(self.task_id)
44
-
45
- @property
46
- def status_and_result(self):
47
- if not self._has_pop:
48
- redis_value = self.redis_db_filter_and_rpc_result.blpop(self.task_id, self.timeout)
49
- self._has_pop = True
50
- if redis_value is not None:
51
- status_and_result_str = redis_value[1]
52
- self._status_and_result = json.loads(status_and_result_str)
53
- self.redis_db_filter_and_rpc_result.lpush(self.task_id, status_and_result_str)
54
- self.redis_db_filter_and_rpc_result.expire(self.task_id, 600)
55
- return self._status_and_result
56
- return None
57
- return self._status_and_result
58
-
59
- def get(self):
60
- # print(self.status_and_result)
61
- if self.status_and_result is not None:
62
- return self.status_and_result['result']
63
- else:
64
- raise HasNotAsyncResult
65
-
66
- @property
67
- def result(self):
68
- return self.get()
69
-
70
- def is_success(self):
71
- return self.status_and_result['success']
72
-
73
- def _run_callback_func(self, callback_func):
74
- callback_func(self.status_and_result)
75
-
76
- def set_callback(self, callback_func: typing.Callable):
77
- """
78
- :param callback_func: 函数结果回调函数,使回调函数自动在线程池中并发运行。
79
- :return:
80
- """
81
-
82
- ''' 用法例如
83
- from test_frame.test_rpc.test_consume import add
84
- def show_result(status_and_result: dict):
85
- """
86
- :param status_and_result: 一个字典包括了函数入参、函数结果、函数是否运行成功、函数运行异常类型
87
- """
88
- print(status_and_result)
89
-
90
- for i in range(100):
91
- async_result = add.push(i, i * 2)
92
- # print(async_result.result) # 执行 .result是获取函数的运行结果,会阻塞当前发布消息的线程直到函数运行完成。
93
- async_result.set_callback(show_result) # 使用回调函数在线程池中并发的运行函数结果
94
- '''
95
- self.callback_run_executor.submit(self._run_callback_func, callback_func)
96
20
 
21
+ from funboost.publishers.msg_result_getter import AsyncResult, AioAsyncResult, HasNotAsyncResult
22
+ from funboost.utils import decorators, time_util
23
+ from funboost import funboost_config_deafult
97
24
 
98
25
  RedisAsyncResult = AsyncResult # 别名
26
+ RedisAioAsyncResult = AioAsyncResult # 别名
99
27
 
100
28
 
101
29
  class PriorityConsumingControlConfig:
@@ -0,0 +1,168 @@
1
+ import asyncio
2
+
3
+ import typing
4
+ import json
5
+ from funboost.concurrent_pool import CustomThreadPoolExecutor
6
+ from funboost.utils import RedisMixin
7
+ from funboost.utils.redis_manager import AioRedisMixin
8
+
9
+
10
+ class HasNotAsyncResult(Exception):
11
+ pass
12
+
13
+
14
+ class AsyncResult(RedisMixin):
15
+ callback_run_executor = CustomThreadPoolExecutor(200)
16
+
17
+ def __init__(self, task_id, timeout=120):
18
+ self.task_id = task_id
19
+ self.timeout = timeout
20
+ self._has_pop = False
21
+ self._status_and_result = None
22
+
23
+ def set_timeout(self, timeout=60):
24
+ self.timeout = timeout
25
+ return self
26
+
27
+ def is_pending(self):
28
+ return not self.redis_db_filter_and_rpc_result.exists(self.task_id)
29
+
30
+ @property
31
+ def status_and_result(self):
32
+ if not self._has_pop:
33
+ redis_value = self.redis_db_filter_and_rpc_result.blpop(self.task_id, self.timeout)
34
+ self._has_pop = True
35
+ if redis_value is not None:
36
+ status_and_result_str = redis_value[1]
37
+ self._status_and_result = json.loads(status_and_result_str)
38
+ self.redis_db_filter_and_rpc_result.lpush(self.task_id, status_and_result_str)
39
+ self.redis_db_filter_and_rpc_result.expire(self.task_id, 600)
40
+ return self._status_and_result
41
+ return None
42
+ return self._status_and_result
43
+
44
+ def get(self):
45
+ # print(self.status_and_result)
46
+ if self.status_and_result is not None:
47
+ return self.status_and_result['result']
48
+ else:
49
+ raise HasNotAsyncResult
50
+
51
+ @property
52
+ def result(self):
53
+ return self.get()
54
+
55
+ def is_success(self):
56
+ if self.status_and_result is not None:
57
+ return self.status_and_result['success']
58
+ else:
59
+ raise HasNotAsyncResult
60
+
61
+ def _run_callback_func(self, callback_func):
62
+ callback_func(self.status_and_result)
63
+
64
+ def set_callback(self, callback_func: typing.Callable):
65
+ """
66
+ :param callback_func: 函数结果回调函数,使回调函数自动在线程池中并发运行。
67
+ :return:
68
+ """
69
+
70
+ ''' 用法例如
71
+ from test_frame.test_rpc.test_consume import add
72
+ def show_result(status_and_result: dict):
73
+ """
74
+ :param status_and_result: 一个字典包括了函数入参、函数结果、函数是否运行成功、函数运行异常类型
75
+ """
76
+ print(status_and_result)
77
+
78
+ for i in range(100):
79
+ async_result = add.push(i, i * 2)
80
+ # print(async_result.result) # 执行 .result是获取函数的运行结果,会阻塞当前发布消息的线程直到函数运行完成。
81
+ async_result.set_callback(show_result) # 使用回调函数在线程池中并发的运行函数结果
82
+ '''
83
+ self.callback_run_executor.submit(self._run_callback_func, callback_func)
84
+
85
+
86
+ class AioAsyncResult(AioRedisMixin):
87
+ ''' 这个是可以用于asyncio的语法环境中。'''
88
+ '''
89
+ import asyncio
90
+
91
+ from funboost import AioAsyncResult
92
+ from test_frame.test_rpc.test_consume import add
93
+
94
+
95
+ async def process_result(status_and_result: dict):
96
+ """
97
+ :param status_and_result: 一个字典包括了函数入参、函数结果、函数是否运行成功、函数运行异常类型
98
+ """
99
+ await asyncio.sleep(1)
100
+ print(status_and_result)
101
+
102
+
103
+ async def test_get_result(i):
104
+ async_result = add.push(i, i * 2)
105
+ aio_async_result = AioAsyncResult(task_id=async_result.task_id) # 这里要使用asyncio语法的类,更方便的配合asyncio异步编程生态
106
+ print(await aio_async_result.result) # 注意这里有个await,如果不await就是打印一个协程对象,不会得到结果。这是asyncio的基本语法,需要用户精通asyncio。
107
+ print(await aio_async_result.status_and_result)
108
+ await aio_async_result.set_callback(process_result) # 你也可以编排任务到loop中
109
+
110
+
111
+ if __name__ == '__main__':
112
+ loop = asyncio.get_event_loop()
113
+ for j in range(100):
114
+ loop.create_task(test_get_result(j))
115
+ loop.run_forever()
116
+
117
+ '''
118
+
119
+ def __init__(self, task_id, timeout=120):
120
+ self.task_id = task_id
121
+ self.timeout = timeout
122
+ self._has_pop = False
123
+ self._status_and_result = None
124
+
125
+ def set_timeout(self, timeout=60):
126
+ self.timeout = timeout
127
+ return self
128
+
129
+ async def is_pending(self):
130
+ is_exists = await self.aioredis_db_filter_and_rpc_result.exists(self.task_id)
131
+ return not is_exists
132
+
133
+ @property
134
+ async def status_and_result(self):
135
+ if not self._has_pop:
136
+ redis_value = await self.aioredis_db_filter_and_rpc_result.blpop(self.task_id, self.timeout)
137
+ self._has_pop = True
138
+ if redis_value is not None:
139
+ status_and_result_str = redis_value[1]
140
+ self._status_and_result = json.loads(status_and_result_str)
141
+ await self.aioredis_db_filter_and_rpc_result.lpush(self.task_id, status_and_result_str)
142
+ await self.aioredis_db_filter_and_rpc_result.expire(self.task_id, 600)
143
+ return self._status_and_result
144
+ return None
145
+ return self._status_and_result
146
+
147
+ async def get(self):
148
+ # print(self.status_and_result)
149
+ if (await self.status_and_result) is not None:
150
+ return (await self.status_and_result)['result']
151
+ else:
152
+ raise HasNotAsyncResult
153
+
154
+ @property
155
+ async def result(self):
156
+ return await self.get()
157
+
158
+ async def is_success(self):
159
+ if (await self.status_and_result) is not None:
160
+ return (await self.status_and_result)['success']
161
+ else:
162
+ raise HasNotAsyncResult
163
+
164
+ async def _run_callback_func(self, callback_func):
165
+ await callback_func(await self.status_and_result)
166
+
167
+ async def set_callback(self, aio_callback_func: typing.Callable):
168
+ asyncio.create_task(self._run_callback_func(callback_func=aio_callback_func))
@@ -3,7 +3,8 @@ import redis2 as redis
3
3
  import redis3
4
4
  from funboost import funboost_config_deafult
5
5
  from funboost.utils import decorators
6
-
6
+ import aioredis
7
+ from aioredis.client import Redis as AioRedis
7
8
 
8
9
  class RedisManager(object):
9
10
  _pool_dict = {}
@@ -89,3 +90,15 @@ class RedisMixin(object):
89
90
  time_tuple = self.redis_db_frame_version3.time()
90
91
  # print(time_tuple)
91
92
  return time_tuple[0] + time_tuple[1] / 1000000
93
+
94
+
95
+ class AioRedisMixin(object):
96
+ @property
97
+ @decorators.cached_method_result
98
+ def aioredis_db_filter_and_rpc_result(self):
99
+ return AioRedis(host=funboost_config_deafult.REDIS_HOST, port=funboost_config_deafult.REDIS_PORT,
100
+ password=funboost_config_deafult.REDIS_PASSWORD, db=funboost_config_deafult.REDIS_DB_FILTER_AND_RPC_RESULT, decode_responses=True)
101
+
102
+
103
+
104
+
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: funboost
3
- Version: 18.8
3
+ Version: 18.9
4
4
  Summary: pip install funboost,python全功能分布式函数调度框架,。支持python所有类型的并发模式和一切知名消息队列中间件,python函数加速器,框架包罗万象,一统编程思维,兼容50% python业务场景,适用范围广。只需要一行代码即可分布式执行python一切函数。旧名字是function_scheduling_distributed_framework
5
5
  Home-page: https://github.com/ydf0509/funboost
6
6
  Author: bfzs
@@ -65,6 +65,7 @@ Requires-Dist: pysnooper
65
65
  Requires-Dist: deprecated
66
66
  Requires-Dist: cryptography
67
67
  Requires-Dist: auto-run-on-remote
68
+ Requires-Dist: aioredis
68
69
 
69
70
 
70
71
  # 1.分布式函数调度框架简介
@@ -1,4 +1,4 @@
1
- funboost/__init__.py,sha256=HvbLiA6zDnkiUi7FCkN0BnXTgDkEAZRJzHgGNutHL8E,19873
1
+ funboost/__init__.py,sha256=yA-RMkUUUGFm93esljMB3aeB9KveQhMWYQCgFYolRO0,19886
2
2
  funboost/constant.py,sha256=rC81k-DiWEquS-4eoUDgQEoTbpavPFuk3jJ3D80dyE8,5627
3
3
  funboost/funboost_config_deafult.py,sha256=bLK7DlFTzL4sWNuK1uTTA-alG2RBZzFyS_ZeUim7Css,6413
4
4
  funboost/helpers.py,sha256=iU1jVyRUuZlwogbnMlRIfXil2hSG64Xuh840pgIeIZg,13699
@@ -79,7 +79,7 @@ funboost/function_result_web/static/js/jquery-1.11.0.min.js,sha256=ryQZ3RXgnqkTz
79
79
  funboost/function_result_web/templates/index.html,sha256=dWe-JFQhsDpoNjSsBF4P6SJWp_KvHX8EP_yECS5r7_o,19501
80
80
  funboost/function_result_web/templates/login.html,sha256=q37dj7O0LeyiV38Zd5P1Qn_qmhjdFomuYTRY1Yk48Bo,2007
81
81
  funboost/publishers/__init__.py,sha256=xqBHlvsJQVPfbdvP84G0LHmVB7-pFBS7vDnX1Uo9pVY,131
82
- funboost/publishers/base_publisher.py,sha256=m5-hTCkDAJLBaKC7Y8BZzVRpH1yXcQLBl889VQ6tfmM,17462
82
+ funboost/publishers/base_publisher.py,sha256=nEL6fFYVn622g3OkqdTDDXLslm2UR8Meyxyg6L5uECE,14851
83
83
  funboost/publishers/confluent_kafka_publisher.py,sha256=uOIzTUwhdsQGBCeAmSUgd4GQm7QMEdUO7eDIsSPNyMQ,3537
84
84
  funboost/publishers/http_publisher.py,sha256=QbVG-dFdKdltCoElHmKpNSMsjpZY3Ibp-r_IzqrkPMk,777
85
85
  funboost/publishers/httpsqs_publisher.py,sha256=7cf5ijwrbp4smq6ofndrKisruAqG0Wzfo_d_7bnLUk4,2783
@@ -88,6 +88,7 @@ funboost/publishers/kombu_publisher.py,sha256=ChX3qVE7Kvdu9XVFCKezV2KAwUqY7EhpvM
88
88
  funboost/publishers/local_python_queue_publisher.py,sha256=veskMS5tjeneYU9HmrJLXZSK9_UT48NzHzcljjOoy3g,1365
89
89
  funboost/publishers/mongomq_publisher.py,sha256=hK2yIwfHctexmUKIjPjvbIjclc2JjzpMC15aIX1WtfI,1327
90
90
  funboost/publishers/mqtt_publisher.py,sha256=NKVDE5R12QL99IXgRjJtF4phyW8QaXKxHkqW5p_kXr4,3050
91
+ funboost/publishers/msg_result_getter.py,sha256=R_tYQUgnZtTUWge--i1j_aYZLY3wysNTTFKCQ2JKQbE,6161
91
92
  funboost/publishers/nats_publisher.py,sha256=hFfaQovij9dm8w-iRN0SgiHHoS_TlrTAjw42dPwCLSA,776
92
93
  funboost/publishers/nsq_publisher.py,sha256=Go4UjLd_Vt4JuVtfkmCuuXrmxUXv1y6NaBQJX6s1XUo,1302
93
94
  funboost/publishers/peewee_publisher.py,sha256=RsYAqBKf_ZLxkGJeZPWExzG4cpUac7weCeNhcSQ9hZc,1095
@@ -128,7 +129,7 @@ funboost/utils/monkey_patches.py,sha256=Q0_jKxOfFrSgrIDSuSZFrgNh6w_LRGaKAITghrIp
128
129
  funboost/utils/mqtt_util.py,sha256=BfCmyYwI-B8VL9499_IuYlJDCbv6ZhwyWThMf8dANOU,3199
129
130
  funboost/utils/paramiko_util.py,sha256=pu67zkgptqNSV9m2Lznezb3zF1AFYvkWJp_6DVKFSPU,4901
130
131
  funboost/utils/rabbitmq_factory.py,sha256=NPzTwG-INZG9aJgkzp-QVk3TgV0rjiuTVT5lmRT77zg,2963
131
- funboost/utils/redis_manager.py,sha256=HBQuHHoj6FTpMNtT6-fKok9gELv0uBdI92ublN2bODM,4151
132
+ funboost/utils/redis_manager.py,sha256=HHjhhkx2pQ8EGnzIBuvPiD4pV3hhuuPmx9JBYdU0zG0,4625
132
133
  funboost/utils/resource_monitoring.py,sha256=vf1htYa3a4wlMfQqksvIINMw8laiXwG5N8NXU2Zm3qQ,5532
133
134
  funboost/utils/show_funboost_flag.py,sha256=A4WB5P7SO9tFux1Y4yIurLmjLj09B973hq3LxEo4HOY,2985
134
135
  funboost/utils/simple_data_class.py,sha256=HgFyyrw2mDuMX6l-re8W6q-6HXwhg2MalpIbP9JKW70,1204
@@ -147,8 +148,8 @@ funboost/utils/pysnooper_ydf/pycompat.py,sha256=ehsCfjsLdwoK0_o5fwYWDo3WeqCVfHW5
147
148
  funboost/utils/pysnooper_ydf/tracer.py,sha256=2leNcEhT0qt2B_7Vn094dep9AG0qnRX94imQHm4Qp8k,19122
148
149
  funboost/utils/pysnooper_ydf/utils.py,sha256=Y0nGXPqdiHBwO93TQAyYNbrzXtcK3_BQXrDVyjcTqVw,2748
149
150
  funboost/utils/pysnooper_ydf/variables.py,sha256=N12-WKrg4GFt3X1aw9c-jwuVbn2wQTNZXscrYP9RM2k,3678
150
- funboost-18.8.dist-info/LICENSE,sha256=HrhfyXIkWY2tGFK11kg7vPCqhgh5DcxleloqdhrpyMY,11558
151
- funboost-18.8.dist-info/METADATA,sha256=NyISOf7Yuc2jLrpSxnL0kGFUc1mLcSj9OO6r6zExvko,25630
152
- funboost-18.8.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
153
- funboost-18.8.dist-info/top_level.txt,sha256=K8WuKnS6MRcEWxP1NvbmCeujJq6TEfbsB150YROlRw0,9
154
- funboost-18.8.dist-info/RECORD,,
151
+ funboost-18.9.dist-info/LICENSE,sha256=HrhfyXIkWY2tGFK11kg7vPCqhgh5DcxleloqdhrpyMY,11558
152
+ funboost-18.9.dist-info/METADATA,sha256=mWjy2FEntPCdsrWHnCD_fqfupK_4y-vH2dbmcSKxUxQ,25655
153
+ funboost-18.9.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
154
+ funboost-18.9.dist-info/top_level.txt,sha256=K8WuKnS6MRcEWxP1NvbmCeujJq6TEfbsB150YROlRw0,9
155
+ funboost-18.9.dist-info/RECORD,,