代码优化
This commit is contained in:
parent
36a0a133c4
commit
45edcdea6b
|
|
@ -29,7 +29,7 @@ class AllTask:
|
|||
if result is not None:
|
||||
print(f"{key} 从Redis缓存中获取到数据")
|
||||
return result
|
||||
print(f"{key} 在redis中获取数据失败,将任务提交到队列")
|
||||
print(f"{key}:{param['shop_id']}:{param['item_id']} 在redis中获取数据失败,将任务提交到队列")
|
||||
# 确保add_task_to_set是异步方法或正确处理
|
||||
self.redis_conn.add_task_to_set(task_data=param)
|
||||
# 任务结束后开始等待
|
||||
|
|
@ -62,13 +62,15 @@ class AllTask:
|
|||
print(f"{params['task_id']} 数据存入mysql失败,失败原因为{e}")
|
||||
|
||||
async def update_task_record(self, data: Dict[str, Any]):
|
||||
print(f"开始修改任务:{data['task_id']} 状态")
|
||||
await self.db_pool.initialize()
|
||||
# 对任务状态进行修改
|
||||
try:
|
||||
params = {"task_id": data["task_id"]}
|
||||
params = (data["task_id"],)
|
||||
where_conditions = "task_id = %s"
|
||||
affected_rows = await self.db_pool.update(table='crawler_task_record_info', set_columns={"status": data["status"]},
|
||||
where_conditions=where_conditions, params=params)
|
||||
|
||||
if affected_rows:
|
||||
print(f"task_id{data['task_id']} 任务完成,任务状态已修改成功")
|
||||
return True
|
||||
|
|
|
|||
Loading…
Reference in New Issue