onestep 0.1.4__tar.gz → 0.1.6__tar.gz
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-0.1.4 → onestep-0.1.6}/PKG-INFO +1 -1
- {onestep-0.1.4 → onestep-0.1.6}/pyproject.toml +2 -1
- {onestep-0.1.4 → onestep-0.1.6}/setup.py +1 -1
- {onestep-0.1.4 → onestep-0.1.6}/src/onestep/__init__.py +11 -4
- {onestep-0.1.4 → onestep-0.1.6}/src/onestep/broker/cron.py +4 -1
- onestep-0.1.6/src/onestep/middleware/__init__.py +6 -0
- onestep-0.1.6/src/onestep/middleware/base.py +17 -0
- onestep-0.1.6/src/onestep/middleware/config.py +77 -0
- {onestep-0.1.4 → onestep-0.1.6}/src/onestep/onestep.py +1 -1
- onestep-0.1.4/src/onestep/middleware/__init__.py +0 -4
- onestep-0.1.4/src/onestep/middleware/base.py +0 -13
- onestep-0.1.4/src/onestep/middleware/config.py +0 -50
- {onestep-0.1.4 → onestep-0.1.6}/README.md +0 -0
- {onestep-0.1.4 → onestep-0.1.6}/src/onestep/broker/__init__.py +0 -0
- {onestep-0.1.4 → onestep-0.1.6}/src/onestep/broker/base.py +0 -0
- {onestep-0.1.4 → onestep-0.1.6}/src/onestep/broker/memory.py +0 -0
- {onestep-0.1.4 → onestep-0.1.6}/src/onestep/broker/rabbitmq.py +0 -0
- {onestep-0.1.4 → onestep-0.1.6}/src/onestep/broker/webhook.py +0 -0
- {onestep-0.1.4 → onestep-0.1.6}/src/onestep/exception.py +0 -0
- {onestep-0.1.4 → onestep-0.1.6}/src/onestep/message.py +0 -0
- {onestep-0.1.4 → onestep-0.1.6}/src/onestep/retry.py +0 -0
- {onestep-0.1.4 → onestep-0.1.6}/src/onestep/signal.py +0 -0
- {onestep-0.1.4 → onestep-0.1.6}/src/onestep/state.py +0 -0
- {onestep-0.1.4 → onestep-0.1.6}/src/onestep/store/__init__.py +0 -0
- {onestep-0.1.4 → onestep-0.1.6}/src/onestep/store/rabbitmq.py +0 -0
- {onestep-0.1.4 → onestep-0.1.6}/src/onestep/worker.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "onestep"
|
|
3
|
-
version = "0.1.
|
|
3
|
+
version = "0.1.6"
|
|
4
4
|
description = ""
|
|
5
5
|
authors = ["miclon <jcnd@163.com>"]
|
|
6
6
|
readme = "README.md"
|
|
@@ -22,6 +22,7 @@ rabbitmq = ["amqpstorm"]
|
|
|
22
22
|
nacos-sdk-python = "^0.1.12"
|
|
23
23
|
redis = "^4.5.1"
|
|
24
24
|
autopep8 = "^2.0.2"
|
|
25
|
+
loguru = "^0.6.0"
|
|
25
26
|
|
|
26
27
|
|
|
27
28
|
[tool.poetry.group.test.dependencies]
|
|
@@ -18,7 +18,7 @@ extras_require = \
|
|
|
18
18
|
|
|
19
19
|
setup_kwargs = {
|
|
20
20
|
'name': 'onestep',
|
|
21
|
-
'version': '0.1.
|
|
21
|
+
'version': '0.1.6',
|
|
22
22
|
'description': '',
|
|
23
23
|
'long_description': '# OneStep\n\n<a href="https://github.com/mic1on/onestep/actions/workflows/test.yml?query=event%3Apush+branch%3Amain" target="_blank">\n <img src="https://github.com/mic1on/onestep/workflows/test%20suite/badge.svg?branch=main&event=push" alt="Test">\n</a>\n<a href="https://pypi.org/project/onestep" target="_blank">\n <img src="https://img.shields.io/pypi/v/onestep.svg" alt="Package version">\n</a>\n\n<a href="https://pypi.org/project/onestep" target="_blank">\n <img src="https://img.shields.io/pypi/pyversions/onestep.svg" alt="Supported Python versions">\n</a>\n\n<hr />\n仅需一步,轻松实现分布式异步任务。\n\n## Brokers\n\n- [x] MemoryBroker\n- [x] CronBroker\n- [x] WebHookBroker\n- [x] RabbitMQBroker\n- [ ] RedisBroker\n- [ ] KafkaBroker\n\n## example\n\n```python\nfrom onestep import step, WebHookBroker\n\n\n# 对外提供一个webhook接口,接收外部的消息\n@step(from_broker=WebHookBroker(path="/push"))\ndef waiting_messages(message):\n print("收到消息:", message)\n\n\nif __name__ == \'__main__\':\n step.start(block=True)\n```\n\n```python\nfrom onestep import step, CronBroker\n\n\n# 每3秒触发一次任务\n@step(from_broker=CronBroker("* * * * * */3", a=1))\ndef cron_task(message):\n assert message.body == {"a": 1}\n return message\n\n\nif __name__ == \'__main__\':\n step.start(block=True)\n```\n\n更多例子请参阅:[examples](example)',
|
|
24
24
|
'author': 'miclon',
|
|
@@ -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
|
]
|
|
@@ -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
|
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
from .base import BaseMiddleware
|
|
2
|
+
from .config import (
|
|
3
|
+
BaseConfigMiddleware, PublishConfigMixin, ConsumeConfigMixin,
|
|
4
|
+
NacosConfigMixin, NacosPublishConfigMiddleware, NacosConsumeConfigMiddleware,
|
|
5
|
+
RedisConfigMixin, RedisPublishConfigMiddleware, RedisConsumeConfigMiddleware
|
|
6
|
+
)
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
class BaseMiddleware:
|
|
2
|
+
|
|
3
|
+
def before_send(self, step, message, *args, **kwargs):
|
|
4
|
+
"""消息发送之前"""
|
|
5
|
+
pass
|
|
6
|
+
|
|
7
|
+
def after_send(self, step, message, *args, **kwargs):
|
|
8
|
+
"""消息发送之后"""
|
|
9
|
+
pass
|
|
10
|
+
|
|
11
|
+
def before_receive(self, step, message, *args, **kwargs):
|
|
12
|
+
"""消息接收之前"""
|
|
13
|
+
pass
|
|
14
|
+
|
|
15
|
+
def after_receive(self, step, message, *args, **kwargs):
|
|
16
|
+
"""消息接收之后"""
|
|
17
|
+
pass
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
from .base import BaseMiddleware
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class BaseConfigMiddleware(BaseMiddleware):
|
|
5
|
+
|
|
6
|
+
def __init__(self, client, *args, **kwargs):
|
|
7
|
+
self.config_key = kwargs.pop('config_key', None)
|
|
8
|
+
self.client = client
|
|
9
|
+
|
|
10
|
+
def process(self, step, message, *args, **kwargs):
|
|
11
|
+
"""实际获取配置的逻辑"""
|
|
12
|
+
config = self.get(self.config_key)
|
|
13
|
+
return config
|
|
14
|
+
|
|
15
|
+
def get(self, key):
|
|
16
|
+
raise NotImplementedError
|
|
17
|
+
|
|
18
|
+
|
|
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:
|
|
36
|
+
|
|
37
|
+
def __init__(self, client, *args, **kwargs):
|
|
38
|
+
super().__init__(client, *args, **kwargs)
|
|
39
|
+
self.config_group = kwargs.pop("config_group", "DEFAULT_GROUP")
|
|
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 的配置"""
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
class NacosConsumeConfigMiddleware(NacosConfigMixin, ConsumeConfigMixin, BaseConfigMiddleware):
|
|
53
|
+
"""消费前附加来自 Nacos 的配置"""
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
class RedisConfigMixin:
|
|
57
|
+
|
|
58
|
+
def __init__(self, client, *args, **kwargs):
|
|
59
|
+
super().__init__(client, *args, **kwargs)
|
|
60
|
+
self.config_group = kwargs.pop('config_group', 'onestep:config')
|
|
61
|
+
|
|
62
|
+
def get(self, key):
|
|
63
|
+
value = self.client.hget(name=self.config_group, key=key) # noqa
|
|
64
|
+
if isinstance(value, bytes):
|
|
65
|
+
value = value.decode()
|
|
66
|
+
return value
|
|
67
|
+
|
|
68
|
+
def set(self, key, value):
|
|
69
|
+
return self.client.hset(name=self.config_group, key=key, value=value) # noqa
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
class RedisPublishConfigMiddleware(RedisConfigMixin, PublishConfigMixin, BaseConfigMiddleware):
|
|
73
|
+
"""发布前附加来自 Redis 的配置"""
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
class RedisConsumeConfigMiddleware(RedisConfigMixin, ConsumeConfigMixin, BaseConfigMiddleware):
|
|
77
|
+
"""消费前附加来自 Redis 的配置"""
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
class BaseMiddleware:
|
|
2
|
-
|
|
3
|
-
def before_send(self, *args, **kwargs):
|
|
4
|
-
"""消息发送之前"""
|
|
5
|
-
|
|
6
|
-
def after_send(self, *args, **kwargs):
|
|
7
|
-
"""消息发送之后"""
|
|
8
|
-
|
|
9
|
-
def before_receive(self, *args, **kwargs):
|
|
10
|
-
"""消息接收之前"""
|
|
11
|
-
|
|
12
|
-
def after_receive(self, *args, **kwargs):
|
|
13
|
-
"""消息接收之后"""
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import redis
|
|
2
|
-
|
|
3
|
-
from .base import BaseMiddleware
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
class BaseConfigMiddleware(BaseMiddleware):
|
|
7
|
-
|
|
8
|
-
def __init__(self, client, *args, **kwargs):
|
|
9
|
-
self.config_key = kwargs.pop('config_key')
|
|
10
|
-
self.client = client
|
|
11
|
-
|
|
12
|
-
def before_send(self, message):
|
|
13
|
-
"""消息发送之前,给消息添加配置"""
|
|
14
|
-
config = self.get(self.config_key)
|
|
15
|
-
message.config = config
|
|
16
|
-
|
|
17
|
-
def get(self, key):
|
|
18
|
-
raise NotImplementedError
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
class NacosConfigMiddleware(BaseConfigMiddleware):
|
|
22
|
-
|
|
23
|
-
def __init__(self, client, *args, **kwargs):
|
|
24
|
-
super().__init__(client, *args, **kwargs)
|
|
25
|
-
self.config_group = kwargs.pop("config_group", "DEFAULT_GROUP")
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
class RedisConfigMiddleware(BaseConfigMiddleware):
|
|
29
|
-
|
|
30
|
-
def __init__(self, client, *args, **kwargs):
|
|
31
|
-
super().__init__(client, *args, **kwargs)
|
|
32
|
-
self.config_group = kwargs.pop('config_group', 'onestep:config')
|
|
33
|
-
|
|
34
|
-
def get(self, key):
|
|
35
|
-
value = self.client.hget(name=self.config_group, key=key)
|
|
36
|
-
if isinstance(value, bytes):
|
|
37
|
-
value = value.decode()
|
|
38
|
-
return value
|
|
39
|
-
|
|
40
|
-
def set(self, key, value):
|
|
41
|
-
return self.client.hset(name=self.config_group, key=key, value=value)
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
if __name__ == '__main__':
|
|
45
|
-
rds_params = {
|
|
46
|
-
}
|
|
47
|
-
rds_client = redis.Redis(**rds_params)
|
|
48
|
-
|
|
49
|
-
rc = RedisConfigMiddleware(client=rds_client)
|
|
50
|
-
print(rc.get("name"))
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|