onestep 0.4.1__tar.gz → 0.4.2__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.

Files changed (26) hide show
  1. {onestep-0.4.1 → onestep-0.4.2}/PKG-INFO +3 -2
  2. {onestep-0.4.1 → onestep-0.4.2}/pyproject.toml +2 -1
  3. {onestep-0.4.1 → onestep-0.4.2}/src/onestep/broker/base.py +3 -3
  4. {onestep-0.4.1 → onestep-0.4.2}/src/onestep/broker/memory.py +1 -1
  5. {onestep-0.4.1 → onestep-0.4.2}/src/onestep/broker/rabbitmq.py +34 -5
  6. {onestep-0.4.1 → onestep-0.4.2}/src/onestep/broker/redis/pubsub.py +2 -2
  7. {onestep-0.4.1 → onestep-0.4.2}/src/onestep/broker/redis/stream.py +2 -2
  8. {onestep-0.4.1 → onestep-0.4.2}/README.md +0 -0
  9. {onestep-0.4.1 → onestep-0.4.2}/src/onestep/__init__.py +0 -0
  10. {onestep-0.4.1 → onestep-0.4.2}/src/onestep/_utils.py +0 -0
  11. {onestep-0.4.1 → onestep-0.4.2}/src/onestep/broker/__init__.py +0 -0
  12. {onestep-0.4.1 → onestep-0.4.2}/src/onestep/broker/cron.py +0 -0
  13. {onestep-0.4.1 → onestep-0.4.2}/src/onestep/broker/redis/__init__.py +0 -0
  14. {onestep-0.4.1 → onestep-0.4.2}/src/onestep/broker/webhook.py +0 -0
  15. {onestep-0.4.1 → onestep-0.4.2}/src/onestep/cli.py +0 -0
  16. {onestep-0.4.1 → onestep-0.4.2}/src/onestep/exception.py +0 -0
  17. {onestep-0.4.1 → onestep-0.4.2}/src/onestep/message.py +0 -0
  18. {onestep-0.4.1 → onestep-0.4.2}/src/onestep/middleware/__init__.py +0 -0
  19. {onestep-0.4.1 → onestep-0.4.2}/src/onestep/middleware/base.py +0 -0
  20. {onestep-0.4.1 → onestep-0.4.2}/src/onestep/middleware/config.py +0 -0
  21. {onestep-0.4.1 → onestep-0.4.2}/src/onestep/middleware/unique.py +0 -0
  22. {onestep-0.4.1 → onestep-0.4.2}/src/onestep/onestep.py +0 -0
  23. {onestep-0.4.1 → onestep-0.4.2}/src/onestep/retry.py +0 -0
  24. {onestep-0.4.1 → onestep-0.4.2}/src/onestep/signal.py +0 -0
  25. {onestep-0.4.1 → onestep-0.4.2}/src/onestep/state.py +0 -0
  26. {onestep-0.4.1 → onestep-0.4.2}/src/onestep/worker.py +0 -0
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.3
2
2
  Name: onestep
3
- Version: 0.4.1
3
+ Version: 0.4.2
4
4
  Summary: 仅需一步,轻松实现分布式异步任务。
5
5
  Author: miclon
6
6
  Author-email: jcnd@163.com
@@ -11,6 +11,7 @@ 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)
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "onestep"
3
- version = "0.4.1"
3
+ version = "0.4.2"
4
4
  description = "仅需一步,轻松实现分布式异步任务。"
5
5
  authors = ["miclon <jcnd@163.com>"]
6
6
  readme = "README.md"
@@ -28,6 +28,7 @@ nacos-sdk-python = "^0.1.12"
28
28
  redis = "^4.5.1"
29
29
  autopep8 = "^2.0.2"
30
30
  loguru = "^0.6.0"
31
+ use-redis = "^0.1.92"
31
32
 
32
33
 
33
34
  [tool.poetry.group.test.dependencies]
@@ -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
  """
@@ -36,7 +36,7 @@ class MemoryBroker(BaseBroker):
36
36
  super().__init__(*args, **kwargs)
37
37
  self.queue = Queue(maxsize)
38
38
 
39
- def publish(self, message: Any):
39
+ def publish(self, message: Any, *args, **kwargs):
40
40
  try:
41
41
  self.queue.put_nowait(message)
42
42
  except FullException:
@@ -30,15 +30,43 @@ class _RabbitMQMessage(Message):
30
30
  class RabbitMQBroker(BaseBroker):
31
31
  message_cls = _RabbitMQMessage
32
32
 
33
- def __init__(self, queue_name, params: Optional[Dict] = None, prefetch: Optional[int] = 1, auto_create=True, *args,
34
- **kwargs):
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
- self.client.send(self.queue_name, message)
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
  """确认消息"""
@@ -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
 
@@ -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
 
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