zenx 0.8.0__py3-none-any.whl → 0.8.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.
zenx/engine.py CHANGED
@@ -61,7 +61,7 @@ class Engine:
61
61
  if self.shutdown_event.is_set():
62
62
  logger.info("shutdown", spider=spider_name)
63
63
  if spider.background_tasks:
64
- logger.debug("waiting", background_tasks=len(spider.background_tasks))
64
+ logger.debug("waiting", background_tasks=len(spider.background_tasks), belong_to="spider")
65
65
  await asyncio.gather(*spider.background_tasks)
66
66
  await client.close()
67
67
  await db.close()
@@ -83,8 +83,6 @@ try:
83
83
  await self._stub.SubmitFeedMessage(feed_message)
84
84
  except grpc.RpcError as e:
85
85
  self.logger.error("processing", exception=str(e), id=item['_id'], feed=self._feed_id, pipeline=self.name)
86
- else:
87
- self.logger.info("processed", id=item['_id'], feed=self._feed_id, pipeline=self.name)
88
86
 
89
87
 
90
88
  async def close(self) -> None:
zenx/pipelines/manager.py CHANGED
@@ -16,7 +16,8 @@ class PipelineManager:
16
16
  self.pipelines = {name:Pipeline.get_pipeline(name)(logger, db, settings) for name in pipeline_names}
17
17
  self.settings = settings
18
18
  self._fire_and_forget_pipelines = [p for p in self.pipelines.values() if p.name != "preprocess"]
19
-
19
+ self._background_tasks = set()
20
+
20
21
 
21
22
  async def start_pipelines(self) -> None:
22
23
  """ connect and monitor """
@@ -36,9 +37,14 @@ class PipelineManager:
36
37
  self.logger.exception("process_item", item=item, pipeline=preprocess_pipeline.name)
37
38
  raise
38
39
  for pipeline in self._fire_and_forget_pipelines:
39
- asyncio.create_task(pipeline.process_item(item, spider))
40
+ t = asyncio.create_task(pipeline.process_item(item, spider))
41
+ self._background_tasks.add(t)
42
+ t.add_done_callback(self._background_tasks.discard)
40
43
 
41
44
 
42
45
  async def close_pipelines(self) -> None:
46
+ if self._background_tasks:
47
+ self.logger.debug("waiting", background_tasks=len(self._background_tasks), belong_to="pipeline_manager")
48
+ await asyncio.gather(*self._background_tasks)
43
49
  for pipeline in self.pipelines.values():
44
50
  await pipeline.close()
@@ -24,6 +24,7 @@ try:
24
24
  self._connected = asyncio.Event()
25
25
  self._ws_client: Optional[websockets.ClientConnection] = None
26
26
  self._monitor_state_task: Optional[asyncio.Task] = None
27
+ self._listening_task: Optional[asyncio.Task] = None
27
28
 
28
29
 
29
30
  async def start(self) -> None:
@@ -37,6 +38,7 @@ try:
37
38
  raise
38
39
  else:
39
40
  self._monitor_state_task = asyncio.create_task(self._monitor_state())
41
+ self._listening_task = asyncio.create_task(self._listen())
40
42
 
41
43
 
42
44
  async def _monitor_state(self) -> None:
@@ -48,6 +50,15 @@ try:
48
50
  await asyncio.sleep(0.5)
49
51
 
50
52
 
53
+ async def _listen(self) -> None:
54
+ try:
55
+ await self._connected.wait()
56
+ async for msg in self._ws_client:
57
+ self.logger.debug("received", msg=msg.decode(), pipeline=self.name)
58
+ except Exception:
59
+ await asyncio.sleep(1)
60
+
61
+
51
62
  async def _connect(self) -> None:
52
63
  self._connected.clear()
53
64
  self.logger.debug("connecting", pipeline=self.name)
@@ -84,12 +95,13 @@ try:
84
95
 
85
96
 
86
97
  async def close(self) -> None:
87
- if self._monitor_state_task and not self._monitor_state_task.done():
88
- self._monitor_state_task.cancel()
89
- try:
90
- await self._monitor_state_task
91
- except asyncio.CancelledError:
92
- pass
98
+ for t in [self._monitor_state_task, self._listening_task]:
99
+ if t and not t.done():
100
+ t.cancel()
101
+ try:
102
+ await t
103
+ except asyncio.CancelledError:
104
+ pass
93
105
  await self._ws_client.close()
94
106
  self.logger.debug("closed", pipeline=self.name)
95
107
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: zenx
3
- Version: 0.8.0
3
+ Version: 0.8.2
4
4
  Summary: mini-framework
5
5
  Requires-Python: >=3.12
6
6
  Requires-Dist: curl-cffi>=0.12.0
@@ -1,7 +1,7 @@
1
1
  zenx/cli.py,sha256=pHKhOTdqI6NQQoYK91waRIMpxCXLYtXEryzVaTbmvqc,2810
2
2
  zenx/debug_runner.py,sha256=B2Jd9A4_EHDa-ohLcwnFIxOV73FagTWXX2fl3qgwlpY,809
3
3
  zenx/discovery.py,sha256=YANVGzy2IG1fYruUud-11Y-ynyO6iEp3EjlHnhIQJQI,1014
4
- zenx/engine.py,sha256=fZ080nkZmCKp0Ra0sGEm9xBQ9dCzU6vT2CWF4ma-QA0,2531
4
+ zenx/engine.py,sha256=CYwvmPSaI1lC-y_DfuOzX_1Ii14fxU8IdfMM7AIrUUU,2551
5
5
  zenx/exceptions.py,sha256=BJXxzwwX2CU6inhppfblx8c8Z6Mhvsk7MAhQ1LAnhBg,37
6
6
  zenx/logger.py,sha256=UmEk0vV1mSCozV7z_DDgCCXdAManDr5wgkrhKiRQtyU,1651
7
7
  zenx/settings.py,sha256=0RLeKcqHJdD1vuYIQtGeXkp2YIvv3tNyz9O8jw620VQ,1008
@@ -11,17 +11,17 @@ zenx/clients/database.py,sha256=AF-L7iYrWRNzUZKn7taveiihpu--mXXC6eWOrMNlqzQ,4806
11
11
  zenx/clients/http.py,sha256=fb6COYot6vidNFRBWgoU6CYEfnYWJP0JuVkydvxsHb4,5700
12
12
  zenx/pipelines/__init__.py,sha256=IxkZ0UpEJdYjLdd-PMcC9PzzzArTBNNcpgKc7NiOe5Y,131
13
13
  zenx/pipelines/base.py,sha256=N_388z5DFMeaU6wMwcClZAbQFWKh4kpAF7eUJhpQevs,1863
14
- zenx/pipelines/google_rpc.py,sha256=8DGcUlE6Th39XgD7WMMxqBMhUkH0kr3l9-cN_1x4CY4,4610
15
- zenx/pipelines/manager.py,sha256=bP2WIMblbWYHOJPU44l_IF3xLD0eHBYV4CCTFZc2FHI,1662
14
+ zenx/pipelines/google_rpc.py,sha256=nR7hNCqAcg1YGWYm3xoj8G8vOTs74lAeYc0dYk842n8,4490
15
+ zenx/pipelines/manager.py,sha256=lm2A_4h8NNdurFfwrrLwx5Z1tqJ9yZp2qgYvwGWd1lc,2017
16
16
  zenx/pipelines/preprocess.py,sha256=zXuhaLdH5KfBi_Bf-K5BgzFEujdmPWWpwYKkpOifT5U,816
17
- zenx/pipelines/websocket.py,sha256=jkRp5a6ro3q2JPAm8qtZWnf0EzFFUFOQgzgSxURXTvk,4359
17
+ zenx/pipelines/websocket.py,sha256=27eda1wpdl2KI8fz78kyiehLFAwzuOhOdYHEgygdnEo,4813
18
18
  zenx/resources/proto/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
19
19
  zenx/resources/proto/feed_pb2.py,sha256=ZyICOLnyuXekkvV4bAHZ1nE1-wwzcYYRRrmRJCMrSoo,2810
20
20
  zenx/resources/proto/feed_pb2_grpc.py,sha256=Mim6FfBgIMj0PmTqHk036nVUMJH3A6I3ts6r1j3bQF8,7441
21
21
  zenx/spiders/__init__.py,sha256=rs5LuqdM2MQlUYiTGJrzkYhzN8_SSLTrR7wGjSRrrSo,25
22
22
  zenx/spiders/base.py,sha256=BGxOvNnjaz6gmZm7NIgYc0RddWDmpIp53ukxprUUd-Y,1932
23
- zenx-0.8.0.dist-info/METADATA,sha256=7-IqNel1NhxaqGWQ4YY38IUVM4mglWRyDgugcT0D6mc,1273
24
- zenx-0.8.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
25
- zenx-0.8.0.dist-info/entry_points.txt,sha256=8JXob2f1VtvzGFris-e9Usqywg7oca-cChDlH9moOZU,38
26
- zenx-0.8.0.dist-info/top_level.txt,sha256=JeXwvK86d7sB-2x-avugFnZIZa33zaHWKI8RHWJR6KY,5
27
- zenx-0.8.0.dist-info/RECORD,,
23
+ zenx-0.8.2.dist-info/METADATA,sha256=iQA1IwASxOkMUH_WPu22DKBLv9gFNkN6zNObL80mqok,1273
24
+ zenx-0.8.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
25
+ zenx-0.8.2.dist-info/entry_points.txt,sha256=8JXob2f1VtvzGFris-e9Usqywg7oca-cChDlH9moOZU,38
26
+ zenx-0.8.2.dist-info/top_level.txt,sha256=JeXwvK86d7sB-2x-avugFnZIZa33zaHWKI8RHWJR6KY,5
27
+ zenx-0.8.2.dist-info/RECORD,,
File without changes