Skip to content

Commit 0aafa65

Browse files
committed
fix: optimize logging for mkdir and refresh; bump version to v0.0.7
1 parent 91916cb commit 0aafa65

3 files changed

Lines changed: 35 additions & 5 deletions

File tree

service/syncJob/jobClient.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ def delFile(self, path, fileName, size):
403403
errMsg = str(e)
404404
self.delHook(path, fileName, None if isPath else size, status, errMsg, isPath, createTime)
405405

406-
def listDir(self, path, firstDst, spec, rootPath, isSrc=True):
406+
def listDir(self, path, firstDst, spec, rootPath, isSrc=True, ignoreError=False):
407407
"""
408408
列出目录
409409
self.job['useCacheT']: 扫描目标目录时,是否使用缓存,0-不使用,1-使用
@@ -415,13 +415,16 @@ def listDir(self, path, firstDst, spec, rootPath, isSrc=True):
415415
:param spec:
416416
:param rootPath:
417417
:param isSrc:
418+
:param ignoreError: 是否忽略错误(不记录日志和回调)
418419
:return:
419420
"""
420421
useCache = 1 if isSrc and not firstDst else self.job[f"useCache{'S' if isSrc else 'T'}"]
421422
scanInterval = self.job[f"scanInterval{'S' if isSrc else 'T'}"]
422423
try:
423424
return self.openlistClient.fileListApi(path, useCache, scanInterval, spec, rootPath)
424425
except Exception as e:
426+
if ignoreError:
427+
raise e
425428
logger = logging.getLogger()
426429
errMsg = G('scan_error').format(G('src' if isSrc else 'dst'), str(e))
427430
logger.error(errMsg)
@@ -441,7 +444,12 @@ def ensurePath(self, path):
441444
try:
442445
self.openlistClient.fileListApi(cur, 0, scanInterval, None, cur)
443446
except Exception:
444-
self.openlistClient.mkdir(cur, scanInterval)
447+
try:
448+
self.openlistClient.mkdir(cur, scanInterval)
449+
except Exception as e:
450+
logger = logging.getLogger()
451+
logger.error(f"Failed to mkdir: {cur}, error: {str(e)}")
452+
raise e
445453

446454
def syncWithHave(self, srcPath, dstPath, spec, srcRootPath, dstRootPath, firstDst):
447455
"""
@@ -459,7 +467,7 @@ def syncWithHave(self, srcPath, dstPath, spec, srcRootPath, dstRootPath, firstDs
459467
try:
460468
srcFiles = self.listDir(srcPath, firstDst, spec, srcRootPath)
461469
try:
462-
dstFiles = self.listDir(dstPath, firstDst, spec, dstRootPath, False)
470+
dstFiles = self.listDir(dstPath, firstDst, spec, dstRootPath, False, ignoreError=True)
463471
except Exception:
464472
self.syncWithOutHave(srcPath, dstPath, spec, srcRootPath, dstRootPath, firstDst)
465473
return
@@ -506,6 +514,8 @@ def syncWithOutHave(self, srcPath, dstPath, spec, srcRootPath, dstRootPath, firs
506514
except Exception as e:
507515
status = 7
508516
errMsg = str(e)
517+
logger = logging.getLogger()
518+
logger.error(f"SyncWithOutHave ensurePath failed: {dstPath}, error: {errMsg}")
509519
# 目录回调
510520
self.copyHook(srcPath, dstPath, None, None, status=status, errMsg=errMsg, isPath=1)
511521
if status != 2:

service/webhook/refreshService.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
import re
22
import os
33
import time
4+
import logging
45

56
from service.openlist import openlistService
67
from service.notify import notifyService
78

89

910
def _refresh_path(client, path):
11+
logger = logging.getLogger()
1012
try:
1113
if not path.endswith('/'):
1214
path = path + '/'
1315
client.fileListApi(path, 0, 0, None, path)
16+
logger.info(f"Refresh success: {path}")
1417
return True, None
1518
except Exception as e:
19+
logger.error(f"Refresh failed: {path}, error: {str(e)}")
1620
return False, str(e)
1721

1822

@@ -64,8 +68,12 @@ def _select_latest_odc_prefix(client, prefix):
6468

6569

6670
def refresh_after_task(job, status):
71+
logger = logging.getLogger()
6772
if status not in [2, 3]:
73+
logger.info(f"Refresh skipped: status {status} not in [2, 3]")
6874
return
75+
logger.info(f"Refresh start: job={job.get('remark')}, status={status}")
76+
6977
openlistId = int(job['openlistId'])
7078
client = openlistService.getClientById(openlistId)
7179
remark = job.get('remark') or ''
@@ -115,6 +123,9 @@ def _expand_targets(env_s):
115123
env_refresh = os.getenv('DST_REFRESH_TV') if is_tv else os.getenv('DST_REFRESH_MOV')
116124
else:
117125
env_refresh = os.getenv('SYNC_REFRESH_TV') if is_tv else os.getenv('SYNC_REFRESH_MOV')
126+
127+
logger.info(f"Refresh env config: dst_used={dst_used}, env_refresh={env_refresh}")
128+
118129
if env_refresh:
119130
raw = [p.strip() for p in re.split(r"[,;:]", env_refresh) if p and p.strip() != '']
120131
tv_prefix = _select_latest_odc_prefix(client, 'tv')
@@ -139,7 +150,11 @@ def _expand_targets(env_s):
139150
seen.add(path)
140151
base_paths = dedup
141152
if not base_paths:
153+
logger.info("Refresh skipped: no base_paths found")
142154
return
155+
156+
logger.info(f"Refresh targets: {base_paths}")
157+
143158
# 解析 Season 并刷新
144159
resolved = []
145160
for base in base_paths:
@@ -152,15 +167,20 @@ def _expand_targets(env_s):
152167
ok_list.append(p)
153168
else:
154169
fail_list.append(f"{p}{msg}")
170+
171+
logger.info(f"Refresh result: ok={len(ok_list)}, fail={len(fail_list)}")
172+
155173
notify_list = notifyService.getNotifyList(True)
156174
if not notify_list:
175+
logger.info("Refresh notify skipped: no notify config")
157176
return
158177
title = ('目录刷新完成 ✔️' if not fail_list else '目录刷新失败 ❌')
159178
content = ("全部目录刷新成功:\n" + "\n".join(ok_list)) if not fail_list else ("以下目录刷新失败:\n" + "\n".join(fail_list))
160179
for notify in notify_list:
161180
try:
162181
notifyService.sendNotify(notify, title, content, False)
163-
except Exception:
182+
except Exception as e:
183+
logger.error(f"Refresh notify failed: {str(e)}")
164184
pass
165185
key = f"{remark}:{status}"
166186
now = time.time()

version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
v0.0.6,latest
1+
v0.0.7,latest
22

33

44
该文件仅第一行有效,表示打包的版本。

0 commit comments

Comments
 (0)