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 +1 -1
- zenx/pipelines/google_rpc.py +0 -2
- zenx/pipelines/manager.py +8 -2
- zenx/pipelines/websocket.py +18 -6
- {zenx-0.8.0.dist-info → zenx-0.8.2.dist-info}/METADATA +1 -1
- {zenx-0.8.0.dist-info → zenx-0.8.2.dist-info}/RECORD +9 -9
- {zenx-0.8.0.dist-info → zenx-0.8.2.dist-info}/WHEEL +0 -0
- {zenx-0.8.0.dist-info → zenx-0.8.2.dist-info}/entry_points.txt +0 -0
- {zenx-0.8.0.dist-info → zenx-0.8.2.dist-info}/top_level.txt +0 -0
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()
|
zenx/pipelines/google_rpc.py
CHANGED
@@ -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()
|
zenx/pipelines/websocket.py
CHANGED
@@ -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
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
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,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=
|
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=
|
15
|
-
zenx/pipelines/manager.py,sha256=
|
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=
|
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.
|
24
|
-
zenx-0.8.
|
25
|
-
zenx-0.8.
|
26
|
-
zenx-0.8.
|
27
|
-
zenx-0.8.
|
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
|
File without changes
|
File without changes
|