onestep 0.4.0__py3-none-any.whl → 0.4.2__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/broker/base.py +3 -3
- onestep/broker/memory.py +1 -1
- onestep/broker/rabbitmq.py +34 -5
- onestep/broker/redis/pubsub.py +2 -2
- onestep/broker/redis/stream.py +2 -2
- onestep/cli.py +18 -2
- {onestep-0.4.0.dist-info → onestep-0.4.2.dist-info}/METADATA +5 -4
- {onestep-0.4.0.dist-info → onestep-0.4.2.dist-info}/RECORD +10 -10
- {onestep-0.4.0.dist-info → onestep-0.4.2.dist-info}/WHEEL +1 -1
- {onestep-0.4.0.dist-info → onestep-0.4.2.dist-info}/entry_points.txt +0 -0
onestep/broker/base.py
CHANGED
|
@@ -43,15 +43,15 @@ class BaseBroker:
|
|
|
43
43
|
def add_middleware(self, middleware: BaseMiddleware):
|
|
44
44
|
self.middlewares.append(middleware)
|
|
45
45
|
|
|
46
|
-
def send(self, message):
|
|
46
|
+
def send(self, message, *args, **kwargs):
|
|
47
47
|
"""对消息进行预处理,然后再发送"""
|
|
48
48
|
if not isinstance(message, Message):
|
|
49
49
|
message = self.message_cls(body=message)
|
|
50
50
|
# TODO: 对消息发送进行N次重试,确保消息发送成功。
|
|
51
|
-
return self.publish(message.to_json())
|
|
51
|
+
return self.publish(message.to_json(), *args, **kwargs)
|
|
52
52
|
|
|
53
53
|
@abc.abstractmethod
|
|
54
|
-
def publish(self, message: Any):
|
|
54
|
+
def publish(self, message: Any, *args, **kwargs):
|
|
55
55
|
"""
|
|
56
56
|
将消息原样发布到 broker 中。如果当前Broker是Job的to_broker, 则必须实现此方法
|
|
57
57
|
"""
|
onestep/broker/memory.py
CHANGED
onestep/broker/rabbitmq.py
CHANGED
|
@@ -30,15 +30,43 @@ class _RabbitMQMessage(Message):
|
|
|
30
30
|
class RabbitMQBroker(BaseBroker):
|
|
31
31
|
message_cls = _RabbitMQMessage
|
|
32
32
|
|
|
33
|
-
def __init__(
|
|
34
|
-
|
|
33
|
+
def __init__(
|
|
34
|
+
self,
|
|
35
|
+
queue_name,
|
|
36
|
+
params: Optional[Dict] = None,
|
|
37
|
+
prefetch: Optional[int] = 1,
|
|
38
|
+
auto_create: Optional[bool]=True,
|
|
39
|
+
queue_params: Optional[Dict]=None,
|
|
40
|
+
*args,
|
|
41
|
+
**kwargs
|
|
42
|
+
):
|
|
43
|
+
"""
|
|
44
|
+
Initializes the RabbitMQ broker.
|
|
45
|
+
|
|
46
|
+
Args:
|
|
47
|
+
queue_name (str): The name of the queue.
|
|
48
|
+
params (Optional[Dict], optional): Parameters for RabbitMQStore. Defaults to None.
|
|
49
|
+
prefetch (Optional[int], optional): Number of messages to prefetch. Defaults to 1.
|
|
50
|
+
auto_create (Optional[bool], optional): Whether to automatically create the queue. Defaults to True.
|
|
51
|
+
queue_params (Optional[Dict], optional): Parameters for queue declaration. Defaults to None.
|
|
52
|
+
*args: Variable length argument list.
|
|
53
|
+
**kwargs: Arbitrary keyword arguments.
|
|
54
|
+
|
|
55
|
+
Attributes:
|
|
56
|
+
queue_name (str): The name of the queue.
|
|
57
|
+
queue (Queue): The queue instance.
|
|
58
|
+
client (RabbitMQStore): The RabbitMQ client instance.
|
|
59
|
+
prefetch (int): Number of messages to prefetch.
|
|
60
|
+
threads (list): List of threads.
|
|
61
|
+
"""
|
|
62
|
+
|
|
35
63
|
super().__init__(*args, **kwargs)
|
|
36
64
|
self.queue_name = queue_name
|
|
37
65
|
self.queue = Queue()
|
|
38
66
|
params = params or {}
|
|
39
67
|
self.client = RabbitMQStore(**params)
|
|
40
68
|
if auto_create:
|
|
41
|
-
self.client.declare_queue(self.queue_name)
|
|
69
|
+
self.client.declare_queue(self.queue_name, **(queue_params or {}))
|
|
42
70
|
self.prefetch = prefetch
|
|
43
71
|
self.threads = []
|
|
44
72
|
|
|
@@ -57,8 +85,9 @@ class RabbitMQBroker(BaseBroker):
|
|
|
57
85
|
self.threads.append(thread)
|
|
58
86
|
return RabbitMQConsumer(self)
|
|
59
87
|
|
|
60
|
-
def publish(self, message: Any):
|
|
61
|
-
|
|
88
|
+
def publish(self, message: Any, properties: Optional[dict] = None, **kwargs):
|
|
89
|
+
"""发布消息"""
|
|
90
|
+
self.client.send(self.queue_name, message, properties=properties, **kwargs)
|
|
62
91
|
|
|
63
92
|
def confirm(self, message: Message):
|
|
64
93
|
"""确认消息"""
|
onestep/broker/redis/pubsub.py
CHANGED
|
@@ -59,12 +59,12 @@ class RedisPubSubBroker(BaseBroker):
|
|
|
59
59
|
self.threads.append(thread)
|
|
60
60
|
return RedisPubSubConsumer(self)
|
|
61
61
|
|
|
62
|
-
def send(self, message: Any):
|
|
62
|
+
def send(self, message: Any, *args, **kwargs):
|
|
63
63
|
"""Publish message to the Redis channel"""
|
|
64
64
|
if not isinstance(message, Message):
|
|
65
65
|
message = self.message_cls(body=message)
|
|
66
66
|
|
|
67
|
-
self.client.publish(self.channel, message.to_json())
|
|
67
|
+
self.client.publish(self.channel, message.to_json(), *args, **kwargs)
|
|
68
68
|
|
|
69
69
|
publish = send
|
|
70
70
|
|
onestep/broker/redis/stream.py
CHANGED
|
@@ -75,12 +75,12 @@ class RedisStreamBroker(BaseBroker):
|
|
|
75
75
|
self.threads.append(thread)
|
|
76
76
|
return RedisStreamConsumer(self)
|
|
77
77
|
|
|
78
|
-
def send(self, message: Any):
|
|
78
|
+
def send(self, message: Any, *args, **kwargs):
|
|
79
79
|
"""对消息进行预处理,然后再发送"""
|
|
80
80
|
if not isinstance(message, Message):
|
|
81
81
|
message = self.message_cls(body=message)
|
|
82
82
|
|
|
83
|
-
self.client.send({"_message": message.to_json()})
|
|
83
|
+
self.client.send({"_message": message.to_json()}, *args, **kwargs)
|
|
84
84
|
|
|
85
85
|
publish = send
|
|
86
86
|
|
onestep/cli.py
CHANGED
|
@@ -22,8 +22,9 @@ def parse_args():
|
|
|
22
22
|
parser = argparse.ArgumentParser(
|
|
23
23
|
description='run onestep'
|
|
24
24
|
)
|
|
25
|
-
parser.
|
|
26
|
-
|
|
25
|
+
group = parser.add_mutually_exclusive_group(required=True)
|
|
26
|
+
group.add_argument(
|
|
27
|
+
"step", nargs='?',
|
|
27
28
|
help="the run step",
|
|
28
29
|
)
|
|
29
30
|
parser.add_argument(
|
|
@@ -39,6 +40,11 @@ def parse_args():
|
|
|
39
40
|
"--path", "-P", default=".", nargs="*", type=str,
|
|
40
41
|
help="the step import path (default: current running directory)"
|
|
41
42
|
)
|
|
43
|
+
group.add_argument(
|
|
44
|
+
"--cron",
|
|
45
|
+
help="the cron expression to test",
|
|
46
|
+
type=str
|
|
47
|
+
)
|
|
42
48
|
return parser.parse_args()
|
|
43
49
|
|
|
44
50
|
|
|
@@ -46,10 +52,20 @@ def main():
|
|
|
46
52
|
args = parse_args()
|
|
47
53
|
for path in args.path:
|
|
48
54
|
sys.path.insert(0, path)
|
|
55
|
+
if args.cron:
|
|
56
|
+
from croniter import croniter
|
|
57
|
+
from datetime import datetime
|
|
58
|
+
cron = croniter(args.cron, datetime.now())
|
|
59
|
+
for _ in range(10):
|
|
60
|
+
print(cron.get_next(datetime))
|
|
61
|
+
return
|
|
62
|
+
|
|
49
63
|
logger.info(f"OneStep {__version__} is start up.")
|
|
50
64
|
try:
|
|
51
65
|
importlib.import_module(args.step)
|
|
52
66
|
step.start(group=args.group, block=True, print_jobs=args.print)
|
|
67
|
+
except ModuleNotFoundError:
|
|
68
|
+
logger.error(f"Module `{args.step}` not found.")
|
|
53
69
|
except KeyboardInterrupt:
|
|
54
70
|
step.shutdown()
|
|
55
71
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
2
|
Name: onestep
|
|
3
|
-
Version: 0.4.
|
|
4
|
-
Summary:
|
|
3
|
+
Version: 0.4.2
|
|
4
|
+
Summary: 仅需一步,轻松实现分布式异步任务。
|
|
5
5
|
Author: miclon
|
|
6
6
|
Author-email: jcnd@163.com
|
|
7
7
|
Requires-Python: >=3.8,<4.0
|
|
@@ -11,11 +11,12 @@ Classifier: Programming Language :: Python :: 3.9
|
|
|
11
11
|
Classifier: Programming Language :: Python :: 3.10
|
|
12
12
|
Classifier: Programming Language :: Python :: 3.11
|
|
13
13
|
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
14
15
|
Provides-Extra: redis
|
|
15
16
|
Requires-Dist: asgiref (>=3.6.0,<4.0.0)
|
|
16
17
|
Requires-Dist: blinker (>=1.5,<2.0)
|
|
17
18
|
Requires-Dist: croniter (>=1.3.8,<2.0.0)
|
|
18
|
-
Requires-Dist: use-rabbitmq (>=0.1
|
|
19
|
+
Requires-Dist: use-rabbitmq (>=0.2.1,<0.3.0)
|
|
19
20
|
Requires-Dist: use-redis (>=0.1.6,<0.2.0) ; extra == "redis"
|
|
20
21
|
Description-Content-Type: text/markdown
|
|
21
22
|
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
onestep/__init__.py,sha256=F38-j9JgPMyUe0zBf-ao-f2ailidPI_DJQE4ddGCOX0,1417
|
|
2
2
|
onestep/_utils.py,sha256=ySYmy-o2o3BurvLfuLWKGXR8TLwug6aTDNMvA3_QjKM,414
|
|
3
3
|
onestep/broker/__init__.py,sha256=L-roNwPZVKsjytOlKCOlyAyvfejI28FyOj9uzfyXcrk,257
|
|
4
|
-
onestep/broker/base.py,sha256=
|
|
4
|
+
onestep/broker/base.py,sha256=G_MzKIbpDSPDx2rx-Q2rwourbcI_faBXQdQZRxjgx8s,4192
|
|
5
5
|
onestep/broker/cron.py,sha256=wKOm4k0IBPgZIq5gHC6ITVFUZwgCQ91AXzgL1eFT1WE,1135
|
|
6
|
-
onestep/broker/memory.py,sha256=
|
|
7
|
-
onestep/broker/rabbitmq.py,sha256=
|
|
6
|
+
onestep/broker/memory.py,sha256=ycOWWHhWhiuNPMDqsbxKbMh8rpt84FlRsJkINLJNX1U,2070
|
|
7
|
+
onestep/broker/rabbitmq.py,sha256=KR1Zn4ciMzrwE5XVCtWvayqmsgAUdu-CW6N_PPlQSO4,4108
|
|
8
8
|
onestep/broker/redis/__init__.py,sha256=lqjvBKpMGf6I34nyJTEAq7XU2a8aQemhMGCbb5aByFI,236
|
|
9
|
-
onestep/broker/redis/pubsub.py,sha256=
|
|
10
|
-
onestep/broker/redis/stream.py,sha256=
|
|
9
|
+
onestep/broker/redis/pubsub.py,sha256=m0QzBT--rftfTXSc6D3wTzfQrwUgv5mEEDnnER7nB9A,2708
|
|
10
|
+
onestep/broker/redis/stream.py,sha256=yUOD-Z0gzU5zNjRW1ZxNwl35i2pbJKTw33xIj0ga3vY,3504
|
|
11
11
|
onestep/broker/webhook.py,sha256=Zg22QxKPqJzdxjBsglUcL7P1RcM8FltcHpHXJiJPYgM,2392
|
|
12
|
-
onestep/cli.py,sha256=
|
|
12
|
+
onestep/cli.py,sha256=JU3xQCy0Zc8Ou6AH4j37_bqw5GQ7C2wll9MWQZFo5jY,1902
|
|
13
13
|
onestep/exception.py,sha256=T-tqfRrJZT9Y85qe-1l-1PcHZzV2jxv-61HAhOc4AKE,753
|
|
14
14
|
onestep/message.py,sha256=W37HKnIDxpd5UmtDbPTw2DTb3lfxu9Vs2KYIiCr5b2s,4057
|
|
15
15
|
onestep/middleware/__init__.py,sha256=MP_45lqr4pecmbzQBnn2-AODQ0N_Fss8nl2SA7Zzljo,347
|
|
@@ -21,7 +21,7 @@ onestep/retry.py,sha256=fPO139hQrcMjXZuQ4QfFaQR57VEqv_EKS2WSz92Ayvc,3706
|
|
|
21
21
|
onestep/signal.py,sha256=tz9bGzTFZeBviG_iaGLfy4OyFKlWat6szEI6kWEGfTA,337
|
|
22
22
|
onestep/state.py,sha256=UVG91CXCabU64X6qgcO0S7RzbBP8ut0ID7aTMww94us,618
|
|
23
23
|
onestep/worker.py,sha256=8Bmbie-KrZxnHbne1RvNL3v8j1PObfd12Yp9jmzAFYg,6855
|
|
24
|
-
onestep-0.4.
|
|
25
|
-
onestep-0.4.
|
|
26
|
-
onestep-0.4.
|
|
27
|
-
onestep-0.4.
|
|
24
|
+
onestep-0.4.2.dist-info/METADATA,sha256=eM1gdjRSpr6zMzxunuv0aa-3KPghbsv14Kql-GOzxC8,2624
|
|
25
|
+
onestep-0.4.2.dist-info/WHEEL,sha256=7dDg4QLnNKTvwIDR9Ac8jJaAmBC_owJrckbC0jjThyA,88
|
|
26
|
+
onestep-0.4.2.dist-info/entry_points.txt,sha256=ZfWnNQqiGujz2PPLjSlKPocOFRryL7Ot0vQ41TU1xw0,44
|
|
27
|
+
onestep-0.4.2.dist-info/RECORD,,
|
|
File without changes
|