async-task-kit 0.1.13__tar.gz → 0.1.14__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.
Files changed (22) hide show
  1. {async_task_kit-0.1.13 → async_task_kit-0.1.14}/PKG-INFO +1 -1
  2. {async_task_kit-0.1.13 → async_task_kit-0.1.14}/async_task_kit/consumer/coroutine.py +6 -3
  3. {async_task_kit-0.1.13 → async_task_kit-0.1.14}/async_task_kit/consumer/process.py +1 -1
  4. {async_task_kit-0.1.13 → async_task_kit-0.1.14}/async_task_kit/consumer/thread.py +1 -1
  5. {async_task_kit-0.1.13 → async_task_kit-0.1.14}/async_task_kit/core/rabbitmq.py +16 -4
  6. {async_task_kit-0.1.13 → async_task_kit-0.1.14}/async_task_kit.egg-info/PKG-INFO +1 -1
  7. {async_task_kit-0.1.13 → async_task_kit-0.1.14}/pyproject.toml +1 -1
  8. {async_task_kit-0.1.13 → async_task_kit-0.1.14}/LICENSE +0 -0
  9. {async_task_kit-0.1.13 → async_task_kit-0.1.14}/README.md +0 -0
  10. {async_task_kit-0.1.13 → async_task_kit-0.1.14}/async_task_kit/__init__.py +0 -0
  11. {async_task_kit-0.1.13 → async_task_kit-0.1.14}/async_task_kit/consumer/__init__.py +0 -0
  12. {async_task_kit-0.1.13 → async_task_kit-0.1.14}/async_task_kit/consumer/base.py +0 -0
  13. {async_task_kit-0.1.13 → async_task_kit-0.1.14}/async_task_kit/core/__init__.py +0 -0
  14. {async_task_kit-0.1.13 → async_task_kit-0.1.14}/async_task_kit/core/processor.py +0 -0
  15. {async_task_kit-0.1.13 → async_task_kit-0.1.14}/async_task_kit/utils/__init__.py +0 -0
  16. {async_task_kit-0.1.13 → async_task_kit-0.1.14}/async_task_kit/utils/env_loader.py +0 -0
  17. {async_task_kit-0.1.13 → async_task_kit-0.1.14}/async_task_kit/utils/logger.py +0 -0
  18. {async_task_kit-0.1.13 → async_task_kit-0.1.14}/async_task_kit.egg-info/SOURCES.txt +0 -0
  19. {async_task_kit-0.1.13 → async_task_kit-0.1.14}/async_task_kit.egg-info/dependency_links.txt +0 -0
  20. {async_task_kit-0.1.13 → async_task_kit-0.1.14}/async_task_kit.egg-info/requires.txt +0 -0
  21. {async_task_kit-0.1.13 → async_task_kit-0.1.14}/async_task_kit.egg-info/top_level.txt +0 -0
  22. {async_task_kit-0.1.13 → async_task_kit-0.1.14}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: async-task-kit
3
- Version: 0.1.13
3
+ Version: 0.1.14
4
4
  Summary: A powerful async task processing kit based on RabbitMQ with Coroutine, Thread, and Process support.
5
5
  Author-email: realwrtoff <realwrtoff@gmail.com>
6
6
  Classifier: Programming Language :: Python :: 3
@@ -18,6 +18,7 @@ class CoroutineConsumer(BaseConsumer):
18
18
  concurrency: int = 1,
19
19
  max_retry: int = 3,
20
20
  retry_delay: int = 30,
21
+ rmq: RabbitMQ | None = None,
21
22
  ):
22
23
  self.amqp_url = amqp_url
23
24
  self.queue_name = queue_name
@@ -26,7 +27,8 @@ class CoroutineConsumer(BaseConsumer):
26
27
  self.max_retry = max_retry
27
28
  self.retry_delay = retry_delay
28
29
 
29
- self._rmq = RabbitMQ(amqp_url)
30
+ self._owns_rmq = rmq is None
31
+ self._rmq = rmq or RabbitMQ(amqp_url)
30
32
  self._stop_event = asyncio.Event()
31
33
 
32
34
  async def start(self):
@@ -93,5 +95,6 @@ class CoroutineConsumer(BaseConsumer):
93
95
 
94
96
  async def stop(self):
95
97
  self._stop_event.set()
96
- await self._rmq.close()
97
- logger.info(f"[CoroutineConsumer] stopped | queue={self.queue_name}")
98
+ if self._owns_rmq:
99
+ await self._rmq.close()
100
+ logger.info(f"[CoroutineConsumer] stopped | queue={self.queue_name}")
@@ -104,4 +104,4 @@ class ProcessConsumer(BaseConsumer):
104
104
 
105
105
  async def stop(self):
106
106
  self._stop_event.set()
107
- logger.info(f"[ProcessConsumer] stopped | queue={self.queue_name}")
107
+ logger.info(f"[ProcessConsumer] stopped | queue={self.queue_name}")
@@ -104,4 +104,4 @@ class ThreadConsumer(BaseConsumer):
104
104
 
105
105
  async def stop(self):
106
106
  self._stop_event.set()
107
- logger.info(f"[ThreadConsumer] stopped | queue={self.queue_name}")
107
+ logger.info(f"[ThreadConsumer] stopped | queue={self.queue_name}")
@@ -12,6 +12,7 @@ from aio_pika.exceptions import (
12
12
  ChannelClosed,
13
13
  AMQPError
14
14
  )
15
+ from aiormq.exceptions import ChannelInvalidStateError
15
16
  from aio_pika.pool import Pool
16
17
 
17
18
  logger = logging.getLogger(__name__)
@@ -63,6 +64,7 @@ class RabbitMQ(BasicQueue):
63
64
  channel_size: int = DEFAULT_CHANNEL_SIZE,
64
65
  heartbeat: int = 60,
65
66
  max_retry_count: int = DEFAULT_MAX_RETRY_COUNT,
67
+
66
68
  ):
67
69
  self.rabbit_url = rabbit_url
68
70
  self.pool_size = pool_size
@@ -157,6 +159,10 @@ class RabbitMQ(BasicQueue):
157
159
  logger.warning("[PUSH] 连接断开,准备重连")
158
160
  await self._invalidate_pools()
159
161
  return None
162
+ except ChannelInvalidStateError:
163
+ logger.warning("[PUSH] 信道 RPC 异常,准备重建 pool")
164
+ await self._invalidate_pools()
165
+ return None
160
166
  except Exception as e:
161
167
  logger.error(f"[PUSH] 异常 queue={queue_name}: {e}", exc_info=True)
162
168
  return None
@@ -172,13 +178,15 @@ class RabbitMQ(BasicQueue):
172
178
  try:
173
179
  async with self._channel_pool.acquire() as channel:
174
180
  queue = await channel.declare_queue(queue_name, durable=durable)
175
- return await asyncio.wait_for(
176
- queue.get(), timeout=self.DEFAULT_POP_TIMEOUT
181
+ # 使用 aio_pika 自带 timeout,勿用 asyncio.wait_for 取消 get(会关闭 channel)
182
+ return await queue.get(
183
+ timeout=self.DEFAULT_POP_TIMEOUT,
184
+ fail=False,
177
185
  )
178
186
  except (QueueEmpty, asyncio.TimeoutError):
179
187
  return None
180
- except (ConnectionClosed, ChannelClosed):
181
- logger.warning("[POP] 连接断开,准备重连")
188
+ except (ConnectionClosed, ChannelClosed, ChannelInvalidStateError):
189
+ logger.warning("[POP] 连接/信道异常,准备重建 pool")
182
190
  await self._invalidate_pools()
183
191
  return None
184
192
  except Exception as e:
@@ -201,6 +209,10 @@ class RabbitMQ(BasicQueue):
201
209
  logger.warning("[QUEUE_LENGTH] 连接断开,准备重连")
202
210
  await self._invalidate_pools()
203
211
  return self.QUEUE_LENGTH_UNAVAILABLE
212
+ except ChannelInvalidStateError:
213
+ logger.warning("[QUEUE_LENGTH] 信道 RPC 异常,准备重建 pool")
214
+ await self._invalidate_pools()
215
+ return self.QUEUE_LENGTH_UNAVAILABLE
204
216
  except Exception as e:
205
217
  logger.error(f"[QUEUE_LENGTH] 异常 queue={queue_name}: {e}", exc_info=True)
206
218
  return self.QUEUE_LENGTH_UNAVAILABLE
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: async-task-kit
3
- Version: 0.1.13
3
+ Version: 0.1.14
4
4
  Summary: A powerful async task processing kit based on RabbitMQ with Coroutine, Thread, and Process support.
5
5
  Author-email: realwrtoff <realwrtoff@gmail.com>
6
6
  Classifier: Programming Language :: Python :: 3
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "async-task-kit"
7
- version = "0.1.13"
7
+ version = "0.1.14"
8
8
  description = "A powerful async task processing kit based on RabbitMQ with Coroutine, Thread, and Process support."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.12"
File without changes