|
17 | 17 | from feapder.db.redisdb import RedisDB |
18 | 18 | from feapder.dedup import Dedup |
19 | 19 | from feapder.network.item import Item, UpdateItem |
20 | | -from feapder.piplines import BasePipline |
| 20 | +from feapder.pipelines import BasePipeline |
21 | 21 | from feapder.utils.log import log |
22 | 22 |
|
23 | 23 | MAX_ITEM_COUNT = 5000 # 缓存中最大item数 |
24 | 24 | UPLOAD_BATCH_MAX_SIZE = 1000 |
25 | 25 |
|
26 | | -MYSQL_PIPLINE_PATH = "feapder.piplines.mysql_pipline.MysqlPipline" |
| 26 | +MYSQL_PIPELINE_PATH = "feapder.pipelines.mysql_pipeline.MysqlPipeline" |
27 | 27 |
|
28 | 28 |
|
29 | 29 | class Singleton(object): |
@@ -59,34 +59,34 @@ def __init__(self, redis_key): |
59 | 59 | # 'xxx:xxx_item': ['id', 'name'...] # 记录redis中item名与需要更新的key对应关系 |
60 | 60 | } |
61 | 61 |
|
62 | | - self._piplines = self.load_piplines() |
| 62 | + self._pipelines = self.load_pipelines() |
63 | 63 |
|
64 | | - self._have_mysql_pipline = MYSQL_PIPLINE_PATH in setting.ITEM_PIPLINES |
65 | | - self._mysql_pipline = None |
| 64 | + self._have_mysql_pipeline = MYSQL_PIPELINE_PATH in setting.ITEM_PIPELINES |
| 65 | + self._mysql_pipeline = None |
66 | 66 |
|
67 | 67 | if setting.ITEM_FILTER_ENABLE and not self.__class__.dedup: |
68 | 68 | self.__class__.dedup = Dedup(to_md5=False) |
69 | 69 |
|
70 | | - def load_piplines(self): |
71 | | - piplines = [] |
72 | | - for pipline_path in setting.ITEM_PIPLINES: |
73 | | - module, class_name = pipline_path.rsplit(".", 1) |
74 | | - pipline_cls = importlib.import_module(module).__getattribute__(class_name) |
75 | | - pipline = pipline_cls() |
76 | | - if not isinstance(pipline, BasePipline): |
77 | | - raise ValueError(f"{pipline_path} 需继承 feapder.piplines.BasePipline") |
78 | | - piplines.append(pipline) |
| 70 | + def load_pipelines(self): |
| 71 | + pipelines = [] |
| 72 | + for pipeline_path in setting.ITEM_PIPELINES: |
| 73 | + module, class_name = pipeline_path.rsplit(".", 1) |
| 74 | + pipeline_cls = importlib.import_module(module).__getattribute__(class_name) |
| 75 | + pipeline = pipeline_cls() |
| 76 | + if not isinstance(pipeline, BasePipeline): |
| 77 | + raise ValueError(f"{pipeline_path} 需继承 feapder.pipelines.BasePipeline") |
| 78 | + pipelines.append(pipeline) |
79 | 79 |
|
80 | | - return piplines |
| 80 | + return pipelines |
81 | 81 |
|
82 | 82 | @property |
83 | | - def mysql_pipline(self): |
84 | | - if not self._mysql_pipline: |
85 | | - module, class_name = MYSQL_PIPLINE_PATH.rsplit(".", 1) |
86 | | - pipline_cls = importlib.import_module(module).__getattribute__(class_name) |
87 | | - self._mysql_pipline = pipline_cls() |
| 83 | + def mysql_pipeline(self): |
| 84 | + if not self._mysql_pipeline: |
| 85 | + module, class_name = MYSQL_PIPELINE_PATH.rsplit(".", 1) |
| 86 | + pipeline_cls = importlib.import_module(module).__getattribute__(class_name) |
| 87 | + self._mysql_pipeline = pipeline_cls() |
88 | 88 |
|
89 | | - return self._mysql_pipline |
| 89 | + return self._mysql_pipeline |
90 | 90 |
|
91 | 91 | def run(self): |
92 | 92 | while not self._thread_stop: |
@@ -244,24 +244,24 @@ def __export_to_db(self, tab_item, datas, is_update=False, update_keys=()): |
244 | 244 | # 打点 校验 |
245 | 245 | self.check_datas(table=to_table, datas=datas) |
246 | 246 |
|
247 | | - for pipline in self._piplines: |
| 247 | + for pipeline in self._pipelines: |
248 | 248 | if is_update: |
249 | | - if not pipline.update_items(to_table, datas, update_keys=update_keys): |
| 249 | + if not pipeline.update_items(to_table, datas, update_keys=update_keys): |
250 | 250 | log.error( |
251 | | - f"{pipline.__class__.__name__} 更新数据失败. table: {to_table} items: {datas}" |
| 251 | + f"{pipeline.__class__.__name__} 更新数据失败. table: {to_table} items: {datas}" |
252 | 252 | ) |
253 | 253 | return False |
254 | 254 |
|
255 | 255 | else: |
256 | | - if not pipline.save_items(to_table, datas): |
| 256 | + if not pipeline.save_items(to_table, datas): |
257 | 257 | log.error( |
258 | | - f"{pipline.__class__.__name__} 保存数据失败. table: {to_table} items: {datas}" |
| 258 | + f"{pipeline.__class__.__name__} 保存数据失败. table: {to_table} items: {datas}" |
259 | 259 | ) |
260 | 260 | return False |
261 | 261 |
|
262 | | - # 若是任务表, 且上面的pipline里没mysql,则需调用mysql更新任务 |
263 | | - if not self._have_mysql_pipline and is_update and to_table.endswith("_task"): |
264 | | - self.mysql_pipline.update_items(to_table, datas, update_keys=update_keys) |
| 262 | + # 若是任务表, 且上面的pipeline里没mysql,则需调用mysql更新任务 |
| 263 | + if not self._have_mysql_pipeline and is_update and to_table.endswith("_task"): |
| 264 | + self.mysql_pipeline.update_items(to_table, datas, update_keys=update_keys) |
265 | 265 |
|
266 | 266 | def __add_item_to_db( |
267 | 267 | self, items, update_items, requests, callbacks, items_fingerprints |
|
0 commit comments