feat: add diagnostic logs for generation flows
This commit is contained in:
+17
-3
@@ -305,9 +305,10 @@ def is_logged_in(account) -> bool:
|
||||
return bool(login_status(account).get("logged_in"))
|
||||
|
||||
|
||||
def open_product(account, item_id) -> CDP:
|
||||
def open_product(account, item_id, on_step=None) -> CDP:
|
||||
"""Open or reuse a product edit tab, navigate to a clean edit URL, and wait ready."""
|
||||
|
||||
_notify_collect_step(on_step, "open_product")
|
||||
host = _cdp_host(account)
|
||||
item_id = str(item_id)
|
||||
url = _product_url(account, item_id)
|
||||
@@ -326,6 +327,7 @@ def open_product(account, item_id) -> CDP:
|
||||
except Exception:
|
||||
pass
|
||||
cdp.send("Page.navigate", {"url": url})
|
||||
_notify_collect_step(on_step, "wait_ready")
|
||||
_wait_ready(cdp)
|
||||
return cdp
|
||||
|
||||
@@ -366,17 +368,20 @@ def download_cover(src, out_path) -> str:
|
||||
return out_path
|
||||
|
||||
|
||||
def collect(account, task) -> dict:
|
||||
def collect(account, task, on_step=None) -> dict:
|
||||
"""Collect current title and cover snapshot before any edits."""
|
||||
|
||||
item_id = _item_id(task)
|
||||
cdp = open_product(account, item_id)
|
||||
cdp = open_product(account, item_id, on_step=on_step)
|
||||
try:
|
||||
_notify_collect_step(on_step, "read_title")
|
||||
old_title = read_title(cdp)
|
||||
_notify_collect_step(on_step, "read_cover")
|
||||
old_cover_src = read_cover_src(cdp)
|
||||
out_path = _get(task, "old_cover_path")
|
||||
if not out_path:
|
||||
out_path = os.path.join(_image_root(account), f"{item_id}_old.jpg")
|
||||
_notify_collect_step(on_step, "download_cover")
|
||||
old_cover_path = download_cover(old_cover_src, out_path)
|
||||
return {
|
||||
"old_title": old_title,
|
||||
@@ -387,6 +392,15 @@ def collect(account, task) -> dict:
|
||||
_close_collected_product(cdp)
|
||||
|
||||
|
||||
|
||||
def _notify_collect_step(callback, step):
|
||||
if callback is None:
|
||||
return
|
||||
try:
|
||||
callback(step)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
def _close_collected_product(cdp):
|
||||
target_id = getattr(cdp, "target_id", None)
|
||||
created_by_app = bool(getattr(cdp, "created_by_app", False))
|
||||
|
||||
Reference in New Issue
Block a user