onestep 0.1.4__py3-none-any.whl → 0.1.6__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 onestep might be problematic. Click here for more details.
- onestep/__init__.py +11 -4
- onestep/broker/cron.py +4 -1
- onestep/middleware/__init__.py +4 -2
- onestep/middleware/base.py +8 -4
- onestep/middleware/config.py +43 -16
- onestep/onestep.py +1 -1
- {onestep-0.1.4.dist-info → onestep-0.1.6.dist-info}/METADATA +1 -1
- {onestep-0.1.4.dist-info → onestep-0.1.6.dist-info}/RECORD +9 -9
- {onestep-0.1.4.dist-info → onestep-0.1.6.dist-info}/WHEEL +0 -0
onestep/__init__.py
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
from .onestep import step
|
|
2
|
-
from .retry import NeverRetry, AlwaysRetry, TimesRetry, RetryIfException, NackErrorCallBack
|
|
2
|
+
from .retry import NeverRetry, AlwaysRetry, TimesRetry, RetryIfException, NackErrorCallBack, LocalAndQueueRetry
|
|
3
3
|
from .broker import (
|
|
4
4
|
BaseBroker, BaseConsumer, BaseLocalBroker, BaseLocalConsumer,
|
|
5
5
|
MemoryBroker, RabbitMQBroker, WebHookBroker, CronBroker
|
|
6
6
|
)
|
|
7
|
-
from .middleware import
|
|
7
|
+
from .middleware import (
|
|
8
|
+
BaseMiddleware, BaseConfigMiddleware,
|
|
9
|
+
NacosPublishConfigMiddleware, NacosConsumeConfigMiddleware,
|
|
10
|
+
RedisPublishConfigMiddleware, RedisConsumeConfigMiddleware,
|
|
11
|
+
)
|
|
8
12
|
|
|
9
13
|
__all__ = [
|
|
10
14
|
'step',
|
|
@@ -24,12 +28,15 @@ __all__ = [
|
|
|
24
28
|
'AlwaysRetry',
|
|
25
29
|
'TimesRetry',
|
|
26
30
|
'RetryIfException',
|
|
31
|
+
'LocalAndQueueRetry',
|
|
27
32
|
#
|
|
28
33
|
'NackErrorCallBack',
|
|
29
34
|
|
|
30
35
|
# middleware
|
|
31
36
|
'BaseMiddleware',
|
|
32
37
|
'BaseConfigMiddleware',
|
|
33
|
-
'
|
|
34
|
-
'
|
|
38
|
+
'NacosPublishConfigMiddleware',
|
|
39
|
+
'NacosConsumeConfigMiddleware',
|
|
40
|
+
'RedisPublishConfigMiddleware',
|
|
41
|
+
'RedisConsumeConfigMiddleware',
|
|
35
42
|
]
|
onestep/broker/cron.py
CHANGED
|
@@ -19,10 +19,13 @@ class CronBroker(BaseLocalBroker):
|
|
|
19
19
|
self.kwargs = kwargs
|
|
20
20
|
self._scheduler()
|
|
21
21
|
|
|
22
|
+
def _real_task(self):
|
|
23
|
+
self.queue.put_nowait(self.kwargs)
|
|
24
|
+
|
|
22
25
|
def _scheduler(self):
|
|
23
26
|
if self.next_fire_time <= datetime.now():
|
|
24
27
|
self.next_fire_time = self.itr.get_next(datetime)
|
|
25
|
-
self.
|
|
28
|
+
self._real_task()
|
|
26
29
|
|
|
27
30
|
threading.Timer(interval=1, function=self._scheduler).start()
|
|
28
31
|
|
onestep/middleware/__init__.py
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
from .base import BaseMiddleware
|
|
1
2
|
from .config import (
|
|
2
|
-
|
|
3
|
+
BaseConfigMiddleware, PublishConfigMixin, ConsumeConfigMixin,
|
|
4
|
+
NacosConfigMixin, NacosPublishConfigMiddleware, NacosConsumeConfigMiddleware,
|
|
5
|
+
RedisConfigMixin, RedisPublishConfigMiddleware, RedisConsumeConfigMiddleware
|
|
3
6
|
)
|
|
4
|
-
from .base import BaseMiddleware
|
onestep/middleware/base.py
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
class BaseMiddleware:
|
|
2
2
|
|
|
3
|
-
def before_send(self, *args, **kwargs):
|
|
3
|
+
def before_send(self, step, message, *args, **kwargs):
|
|
4
4
|
"""消息发送之前"""
|
|
5
|
+
pass
|
|
5
6
|
|
|
6
|
-
def after_send(self, *args, **kwargs):
|
|
7
|
+
def after_send(self, step, message, *args, **kwargs):
|
|
7
8
|
"""消息发送之后"""
|
|
9
|
+
pass
|
|
8
10
|
|
|
9
|
-
def before_receive(self, *args, **kwargs):
|
|
11
|
+
def before_receive(self, step, message, *args, **kwargs):
|
|
10
12
|
"""消息接收之前"""
|
|
13
|
+
pass
|
|
11
14
|
|
|
12
|
-
def after_receive(self, *args, **kwargs):
|
|
15
|
+
def after_receive(self, step, message, *args, **kwargs):
|
|
13
16
|
"""消息接收之后"""
|
|
17
|
+
pass
|
onestep/middleware/config.py
CHANGED
|
@@ -1,50 +1,77 @@
|
|
|
1
|
-
import redis
|
|
2
|
-
|
|
3
1
|
from .base import BaseMiddleware
|
|
4
2
|
|
|
5
3
|
|
|
6
4
|
class BaseConfigMiddleware(BaseMiddleware):
|
|
7
5
|
|
|
8
6
|
def __init__(self, client, *args, **kwargs):
|
|
9
|
-
self.config_key = kwargs.pop('config_key')
|
|
7
|
+
self.config_key = kwargs.pop('config_key', None)
|
|
10
8
|
self.client = client
|
|
11
9
|
|
|
12
|
-
def
|
|
13
|
-
"""
|
|
10
|
+
def process(self, step, message, *args, **kwargs):
|
|
11
|
+
"""实际获取配置的逻辑"""
|
|
14
12
|
config = self.get(self.config_key)
|
|
15
|
-
|
|
13
|
+
return config
|
|
16
14
|
|
|
17
15
|
def get(self, key):
|
|
18
16
|
raise NotImplementedError
|
|
19
17
|
|
|
20
18
|
|
|
21
|
-
class
|
|
19
|
+
class PublishConfigMixin:
|
|
20
|
+
def before_receive(self, step, message, *args, **kwargs):
|
|
21
|
+
"""消息发送之前,给消息添加配置"""
|
|
22
|
+
config = self.process(step, message, *args, **kwargs) # noqa
|
|
23
|
+
# 持久性,会跟随消息传递到其他 broker
|
|
24
|
+
message.extra['config'] = config
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class ConsumeConfigMixin:
|
|
28
|
+
def before_receive(self, step, message, *args, **kwargs):
|
|
29
|
+
"""消息消费之前,给消息附加配置"""
|
|
30
|
+
config = self.process(step, message, *args, **kwargs) # noqa
|
|
31
|
+
# 一次性,不跟随消息传递到其他 broker
|
|
32
|
+
message.config = config
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class NacosConfigMixin:
|
|
22
36
|
|
|
23
37
|
def __init__(self, client, *args, **kwargs):
|
|
24
38
|
super().__init__(client, *args, **kwargs)
|
|
25
39
|
self.config_group = kwargs.pop("config_group", "DEFAULT_GROUP")
|
|
26
40
|
|
|
41
|
+
def get(self, key):
|
|
42
|
+
pass
|
|
43
|
+
|
|
44
|
+
def set(self, key, value):
|
|
45
|
+
pass
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class NacosPublishConfigMiddleware(NacosConfigMixin, PublishConfigMixin, BaseConfigMiddleware):
|
|
49
|
+
"""发布前附加来自 Nacos 的配置"""
|
|
27
50
|
|
|
28
|
-
|
|
51
|
+
|
|
52
|
+
class NacosConsumeConfigMiddleware(NacosConfigMixin, ConsumeConfigMixin, BaseConfigMiddleware):
|
|
53
|
+
"""消费前附加来自 Nacos 的配置"""
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
class RedisConfigMixin:
|
|
29
57
|
|
|
30
58
|
def __init__(self, client, *args, **kwargs):
|
|
31
59
|
super().__init__(client, *args, **kwargs)
|
|
32
60
|
self.config_group = kwargs.pop('config_group', 'onestep:config')
|
|
33
61
|
|
|
34
62
|
def get(self, key):
|
|
35
|
-
value = self.client.hget(name=self.config_group, key=key)
|
|
63
|
+
value = self.client.hget(name=self.config_group, key=key) # noqa
|
|
36
64
|
if isinstance(value, bytes):
|
|
37
65
|
value = value.decode()
|
|
38
66
|
return value
|
|
39
67
|
|
|
40
68
|
def set(self, key, value):
|
|
41
|
-
return self.client.hset(name=self.config_group, key=key, value=value)
|
|
69
|
+
return self.client.hset(name=self.config_group, key=key, value=value) # noqa
|
|
70
|
+
|
|
42
71
|
|
|
72
|
+
class RedisPublishConfigMiddleware(RedisConfigMixin, PublishConfigMixin, BaseConfigMiddleware):
|
|
73
|
+
"""发布前附加来自 Redis 的配置"""
|
|
43
74
|
|
|
44
|
-
if __name__ == '__main__':
|
|
45
|
-
rds_params = {
|
|
46
|
-
}
|
|
47
|
-
rds_client = redis.Redis(**rds_params)
|
|
48
75
|
|
|
49
|
-
|
|
50
|
-
|
|
76
|
+
class RedisConsumeConfigMiddleware(RedisConfigMixin, ConsumeConfigMixin, BaseConfigMiddleware):
|
|
77
|
+
"""消费前附加来自 Redis 的配置"""
|
onestep/onestep.py
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
onestep/__init__.py,sha256=
|
|
1
|
+
onestep/__init__.py,sha256=IUElKqBNhQLtKYQHwYdk67bLeavgb-D9hX0EhY1vdf0,1055
|
|
2
2
|
onestep/broker/__init__.py,sha256=_u2FH9lFKcqau4tTFuj4V3NaVEH0EjImIedl_nlrU7U,221
|
|
3
3
|
onestep/broker/base.py,sha256=HFZ4d0zi5DvwksZDIB7h01kwvY4f8wsEjNbht9uTt7U,4310
|
|
4
|
-
onestep/broker/cron.py,sha256=
|
|
4
|
+
onestep/broker/cron.py,sha256=D782X0bY3AxeL2-NCSEUPkSh591VMgQUYwYaH8c9ZT8,957
|
|
5
5
|
onestep/broker/memory.py,sha256=ILDfYCbMuMmYcZW09jVCdkAg3IQcC-dHkGHIgd8Wh4Q,151
|
|
6
6
|
onestep/broker/rabbitmq.py,sha256=gatzaaRPANaMWVgc9zyupFVTM7xuDWm9GjmFeukWarY,1997
|
|
7
7
|
onestep/broker/webhook.py,sha256=zt__4Lp7jX8B3xo2v64DAqLGnd8aV7ElBsgQZqN2i1w,2144
|
|
8
8
|
onestep/exception.py,sha256=ymwSA_EvHT4Kavs-w0RMmyMrqx4aGZtttAsN8StXj5c,715
|
|
9
9
|
onestep/message.py,sha256=5im6gcH8BWv0Fq6LOxwOZ5DzySC7Ur0jeljPzUQBPNs,2874
|
|
10
|
-
onestep/middleware/__init__.py,sha256=
|
|
11
|
-
onestep/middleware/base.py,sha256=
|
|
12
|
-
onestep/middleware/config.py,sha256=
|
|
13
|
-
onestep/onestep.py,sha256=
|
|
10
|
+
onestep/middleware/__init__.py,sha256=Lv8DbJTgym0ckSKXz_Qfc6we3SUupMt5feHy0gnDi8Q,286
|
|
11
|
+
onestep/middleware/base.py,sha256=JzpSV69LvZXz9b6TyihKjJqO3b-dWzj9Y24jBwIyrEI,450
|
|
12
|
+
onestep/middleware/config.py,sha256=WZIvGXhpdSQRAFTbEWXcZdnhFcbvhGkLdkFIj-_QuZM,2438
|
|
13
|
+
onestep/onestep.py,sha256=vCc5rP75IndID5JBB1-dVfxhNFvbXTf1B1WTxaCtpqo,6262
|
|
14
14
|
onestep/retry.py,sha256=UOrakSV5z97L1VzMRo8p1G6Zmvglu7tJp98vIXdZj40,1904
|
|
15
15
|
onestep/signal.py,sha256=o8KD58jL6lM35gDHVgr1lEspZqFdkMUNJAD-wuouUVo,293
|
|
16
16
|
onestep/state.py,sha256=UVG91CXCabU64X6qgcO0S7RzbBP8ut0ID7aTMww94us,618
|
|
17
17
|
onestep/store/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
18
18
|
onestep/store/rabbitmq.py,sha256=if3fXp_CBK-b4i0Qsb4owfiPPYtQ1biF2OFU6iTRRAE,4170
|
|
19
19
|
onestep/worker.py,sha256=SsowMZSav0f5ocL5RfnwdF2DlN0UNvxO4RK574OWrU0,3517
|
|
20
|
-
onestep-0.1.
|
|
21
|
-
onestep-0.1.
|
|
22
|
-
onestep-0.1.
|
|
20
|
+
onestep-0.1.6.dist-info/WHEEL,sha256=vVCvjcmxuUltf8cYhJ0sJMRDLr1XsPuxEId8YDzbyCY,88
|
|
21
|
+
onestep-0.1.6.dist-info/METADATA,sha256=CajYNhwdtMzZv1qTWtNae67XkCLO9P6gaP6iM3VjshE,1992
|
|
22
|
+
onestep-0.1.6.dist-info/RECORD,,
|
|
File without changes
|