e66f7fed8c
- wx_poc_signal 进程内存信号(device_id→source), 只对 WX_POC_TEST_DEVICE_ID 生效 - 收图 image → set_pending(测试设备, meituan) - POST /device/heartbeat 返回 HeartbeatResponse, 该设备有信号则带回 pending_compare 并清除 - 心跳 schema OkResponse→HeartbeatResponse, 老前端不读 body 向后兼容 - WX_POC_TEST_DEVICE_ID 空=不触发任何设备(部署零风险, 待填测试机 id) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
28 lines
995 B
Python
28 lines
995 B
Python
"""微信截图比价 PoC:进程内存的"待比价"信号(单 worker 够用, 重启即失效, PoC 可接受)。
|
|
|
|
收图端点 set_pending(device_id, source) → 该设备下次心跳 pop_pending 取走并清除 →
|
|
心跳响应带回 → 前端弹选平台窗。只对 settings.WX_POC_TEST_DEVICE_ID 写入, 不碰其他设备。
|
|
后续接真识别 / openid↔device 绑定时整体替换本模块。
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import threading
|
|
|
|
_lock = threading.Lock()
|
|
_pending: dict[str, str] = {} # device_id -> source_platform(如 "meituan")
|
|
|
|
|
|
def set_pending(device_id: str, source_platform: str) -> None:
|
|
if not device_id:
|
|
return
|
|
with _lock:
|
|
_pending[device_id] = source_platform
|
|
|
|
|
|
def pop_pending(device_id: str) -> str | None:
|
|
"""取出并清除该设备的待比价信号;无则 None。心跳每帧调, 取到即消费(只弹一次)。"""
|
|
if not device_id:
|
|
return None
|
|
with _lock:
|
|
return _pending.pop(device_id, None)
|