zenx 0.6.9__py3-none-any.whl → 0.7.0__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/pipelines/manager.py +14 -10
- {zenx-0.6.9.dist-info → zenx-0.7.0.dist-info}/METADATA +1 -1
- {zenx-0.6.9.dist-info → zenx-0.7.0.dist-info}/RECORD +6 -6
- {zenx-0.6.9.dist-info → zenx-0.7.0.dist-info}/WHEEL +0 -0
- {zenx-0.6.9.dist-info → zenx-0.7.0.dist-info}/entry_points.txt +0 -0
- {zenx-0.6.9.dist-info → zenx-0.7.0.dist-info}/top_level.txt +0 -0
zenx/pipelines/manager.py
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
import asyncio
|
1
2
|
from typing import Dict, List
|
2
3
|
from structlog import BoundLogger
|
3
4
|
|
@@ -12,29 +13,32 @@ class PipelineManager:
|
|
12
13
|
|
13
14
|
def __init__(self, pipeline_names: List[str], logger: BoundLogger, db: DBClient, settings: Settings) -> None:
|
14
15
|
self.logger = logger
|
15
|
-
self.pipelines =
|
16
|
+
self.pipelines = {name:Pipeline.get_pipeline(name)(logger, db, settings) for name in pipeline_names}
|
16
17
|
self.settings = settings
|
18
|
+
self._fire_and_forget_pipelines = [p for p in self.pipelines.values() if p.name != "preprocess"]
|
17
19
|
|
18
20
|
|
19
21
|
async def start_pipelines(self) -> None:
|
20
22
|
""" connect and monitor """
|
21
|
-
for pipeline in self.pipelines:
|
23
|
+
for pipeline in self.pipelines.values():
|
22
24
|
await pipeline.start()
|
23
25
|
|
24
26
|
|
25
|
-
async def process_item(self, item: Dict, spider: str) ->
|
26
|
-
|
27
|
+
async def process_item(self, item: Dict, spider: str) -> None:
|
28
|
+
preprocess_pipeline = self.pipelines.get("preprocess")
|
29
|
+
if preprocess_pipeline:
|
27
30
|
try:
|
28
|
-
item = await
|
31
|
+
item = await preprocess_pipeline.process_item(item, spider)
|
29
32
|
except DropItem:
|
30
|
-
self.logger.debug("dropped", id=item.get("_id"))
|
31
|
-
|
33
|
+
self.logger.debug("dropped", id=item.get("_id"), pipeline=preprocess_pipeline.name)
|
34
|
+
return
|
32
35
|
except Exception:
|
33
|
-
self.logger.exception("process_item", pipeline=
|
36
|
+
self.logger.exception("process_item", item=item, pipeline=preprocess_pipeline.name)
|
34
37
|
raise
|
35
|
-
|
38
|
+
for pipeline in self._fire_and_forget_pipelines:
|
39
|
+
asyncio.create_task(pipeline.process_item(item, spider))
|
36
40
|
|
37
41
|
|
38
42
|
async def close_pipelines(self) -> None:
|
39
|
-
for pipeline in self.pipelines:
|
43
|
+
for pipeline in self.pipelines.values():
|
40
44
|
await pipeline.close()
|
@@ -12,7 +12,7 @@ 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
14
|
zenx/pipelines/google_rpc.py,sha256=F7p5ml9W1UliZbrDrF9MFNVKlCP5pG1WpO6rdmBgKp8,4707
|
15
|
-
zenx/pipelines/manager.py,sha256=
|
15
|
+
zenx/pipelines/manager.py,sha256=bP2WIMblbWYHOJPU44l_IF3xLD0eHBYV4CCTFZc2FHI,1662
|
16
16
|
zenx/pipelines/preprocess.py,sha256=k1Ake8H3nm_S_0ZnruyXAl7cFlBhLn-wpQZHuovIH4o,774
|
17
17
|
zenx/pipelines/websocket.py,sha256=74XIV7_YbBngCgqKP3ZiBpDfQte-VB2G4kjNsZyycIc,4456
|
18
18
|
zenx/resources/proto/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
@@ -20,8 +20,8 @@ zenx/resources/proto/feed_pb2.py,sha256=ZyICOLnyuXekkvV4bAHZ1nE1-wwzcYYRRrmRJCMr
|
|
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=YB-KqsAzfIUTzDMy5_ElgW1mul-I4Ltft6JAJxpy4hg,1672
|
23
|
-
zenx-0.
|
24
|
-
zenx-0.
|
25
|
-
zenx-0.
|
26
|
-
zenx-0.
|
27
|
-
zenx-0.
|
23
|
+
zenx-0.7.0.dist-info/METADATA,sha256=aMtFlE8YY8qgo-DPOg0xz4igPppYrBBro8yXYxcnI5I,1273
|
24
|
+
zenx-0.7.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
25
|
+
zenx-0.7.0.dist-info/entry_points.txt,sha256=8JXob2f1VtvzGFris-e9Usqywg7oca-cChDlH9moOZU,38
|
26
|
+
zenx-0.7.0.dist-info/top_level.txt,sha256=JeXwvK86d7sB-2x-avugFnZIZa33zaHWKI8RHWJR6KY,5
|
27
|
+
zenx-0.7.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|