Merge branch 'hugo-shipping-notice' into test
This commit is contained in:
commit
76583c4e5a
98 files changed
+2202
-1475
No files matched your search
@@ -68,7 +68,7 @@ def recover_stale_waiting_source_jobs() -> int:
|
||||
from flask import current_app
|
||||
|
||||
try:
|
||||
timeout = max(60, int(current_app.config.get('SHIPPING_NOTICE_RPA_RECEIPT_TIMEOUT_SECONDS', 900)))
|
||||
timeout = max(60, int(current_app.config.get('FREIGHT_RPA_RECEIPT_TIMEOUT_SECONDS', 900)))
|
||||
except (TypeError, ValueError):
|
||||
timeout = 900
|
||||
cutoff = datetime.utcnow() - timedelta(seconds=timeout)
|
||||
|
||||
@@ -79,7 +79,7 @@ def finalize_receipt_schedule_run_if_complete(schedule_run_id: int) -> dict:
|
||||
def _receipt_timeout_seconds() -> int:
|
||||
"""读取收料回调等待上限;超时只标记失败,不会自动重试或重发。"""
|
||||
try:
|
||||
return max(60, int(current_app.config.get('SHIPPING_NOTICE_RPA_RECEIPT_TIMEOUT_SECONDS', 900)))
|
||||
return max(60, int(current_app.config.get('FREIGHT_RPA_RECEIPT_TIMEOUT_SECONDS', 900)))
|
||||
except (TypeError, ValueError):
|
||||
return 900
|
||||
|
||||
|
||||
@@ -39,14 +39,14 @@ _EMPTY_ARCHIVE_SUMMARY: dict[str, Any] = {
|
||||
def get_inventory_archive_dir() -> str:
|
||||
"""返回库存 RPA 原始 ZIP 归档根目录(自动创建)。"""
|
||||
archive_dir = Path(
|
||||
current_app.config.get("SHIPPING_NOTICE_RPA_INVENTORY_ARCHIVE_DIR")
|
||||
current_app.config.get("FREIGHT_RPA_INVENTORY_ARCHIVE_DIR")
|
||||
if current_app
|
||||
else ""
|
||||
)
|
||||
if not str(archive_dir):
|
||||
from app.core.config.settings import Config
|
||||
|
||||
archive_dir = Path(Config.SHIPPING_NOTICE_RPA_INVENTORY_ARCHIVE_DIR)
|
||||
archive_dir = Path(Config.FREIGHT_RPA_INVENTORY_ARCHIVE_DIR)
|
||||
archive_dir.mkdir(parents=True, exist_ok=True)
|
||||
return str(archive_dir)
|
||||
|
||||
@@ -251,7 +251,7 @@ def _is_allowed_inventory_archive_path(zip_path: Path) -> bool:
|
||||
"""
|
||||
校验归档 ZIP 路径是否安全可下载。
|
||||
|
||||
核心逻辑:文件存在、后缀为 .zip、真实路径必须在 SHIPPING_NOTICE_RPA_INVENTORY_ARCHIVE_DIR 内。
|
||||
核心逻辑:文件存在、后缀为 .zip、真实路径必须在 FREIGHT_RPA_INVENTORY_ARCHIVE_DIR 内。
|
||||
"""
|
||||
resolved = zip_path.resolve()
|
||||
if resolved.suffix.lower() != ".zip":
|
||||
@@ -272,7 +272,7 @@ def resolve_inventory_raw_zip_download(run: ScheduleRun) -> tuple[Path, str]:
|
||||
解析 run 已归档的原始库存 ZIP 路径供下载接口 send_file。
|
||||
|
||||
核心逻辑:读取 summary.raw_inventory_zip_path,校验文件存在、后缀为 .zip、
|
||||
且真实路径位于 SHIPPING_NOTICE_RPA_INVENTORY_ARCHIVE_DIR 内;任一不满足则 404。
|
||||
且真实路径位于 FREIGHT_RPA_INVENTORY_ARCHIVE_DIR 内;任一不满足则 404。
|
||||
|
||||
Returns:
|
||||
tuple[Path, str]: 归档 ZIP 绝对路径与建议下载文件名。
|
||||
|
||||
@@ -19,7 +19,10 @@ from app.models import ScheduleRun, ScheduleTask
|
||||
from app.services.schedule.shipping_inventory_rpa_finalize import AWAITING_RPA_CALLBACK_STATUS
|
||||
from app.services.shipping_notice.inventory_source_repository import list_database_inventory_sources
|
||||
from app.services.shipping_notice.rpa import write_inventory_export_batch_trigger
|
||||
from app.services.shipping_notice.rpa_worker_heartbeat import RPA_WORKER_OFFLINE_MESSAGE
|
||||
from app.services.shipping_notice.rpa_worker_heartbeat import (
|
||||
RPA_WORKER_OFFLINE_MESSAGE,
|
||||
assert_inventory_rpa_worker_ready,
|
||||
)
|
||||
|
||||
ScheduleExecuteResult = tuple[int, int, int, int, list[dict[str, Any]], list[str], list[dict[str, Any]]]
|
||||
|
||||
@@ -121,6 +124,8 @@ def run_shipping_inventory_rpa_schedule(task: ScheduleTask, run: ScheduleRun) ->
|
||||
|
||||
run_no = run.run_no or f"RUN{datetime.utcnow().strftime('%Y%m%d%H%M%S')}"
|
||||
try:
|
||||
# 写 trigger 前强制就绪检查:worker 离线立即 failed,不进入 awaiting_rpa_callback。
|
||||
assert_inventory_rpa_worker_ready()
|
||||
trigger_path = write_inventory_export_batch_trigger(
|
||||
run_no,
|
||||
sources,
|
||||
|
||||
@@ -26,17 +26,17 @@ def _fernet() -> Fernet:
|
||||
Raises:
|
||||
ServiceUnavailableError: 未配置或配置了无效的主密钥。
|
||||
"""
|
||||
key = str(current_app.config.get('SHIPPING_NOTICE_RPA_CREDENTIAL_KEY') or '').strip()
|
||||
key = str(current_app.config.get('FREIGHT_RPA_CREDENTIAL_KEY') or '').strip()
|
||||
if not key:
|
||||
raise ServiceUnavailableError(
|
||||
'SHIPPING_NOTICE_RPA_CREDENTIAL_KEY is not configured',
|
||||
'FREIGHT_RPA_CREDENTIAL_KEY is not configured',
|
||||
code='SHIPPING.RPA_CREDENTIAL_KEY_MISSING',
|
||||
)
|
||||
try:
|
||||
return Fernet(key.encode('ascii'))
|
||||
except (ValueError, UnicodeEncodeError) as exc:
|
||||
raise ServiceUnavailableError(
|
||||
'SHIPPING_NOTICE_RPA_CREDENTIAL_KEY is invalid',
|
||||
'FREIGHT_RPA_CREDENTIAL_KEY is invalid',
|
||||
code='SHIPPING.RPA_CREDENTIAL_KEY_INVALID',
|
||||
) from exc
|
||||
|
||||
|
||||
@@ -420,7 +420,7 @@ def _auto_upload_enabled() -> bool:
|
||||
def _rpa_upload_timeout_seconds() -> int:
|
||||
"""货代上传 RPA 等待回调超时秒数。"""
|
||||
try:
|
||||
return max(int(current_app.config.get('SHIPPING_NOTICE_RPA_UPLOAD_TIMEOUT_SECONDS') or 30), 1)
|
||||
return max(int(current_app.config.get('FREIGHT_RPA_UPLOAD_TIMEOUT_SECONDS') or 30), 1)
|
||||
except (TypeError, ValueError):
|
||||
return 30
|
||||
|
||||
|
||||
@@ -219,7 +219,7 @@ def _expire_timed_out_runs(source: ShippingInventorySource) -> None:
|
||||
同一 RPA Profile 的批量站点由 Windows Worker 串行执行。每个站点沿用单站
|
||||
等待窗口会让排在后面的站点尚未被领取就超时,因此同组按站点数量线性扩展。
|
||||
"""
|
||||
timeout = max(1, int(current_app.config['SHIPPING_NOTICE_RPA_INVENTORY_TIMEOUT_SECONDS']))
|
||||
timeout = max(1, int(current_app.config['FREIGHT_RPA_INVENTORY_TIMEOUT_SECONDS']))
|
||||
runs = ShippingInventoryConfigurationTestRun.query.filter(
|
||||
ShippingInventoryConfigurationTestRun.inventory_source_id == source.id,
|
||||
ShippingInventoryConfigurationTestRun.status.in_(['awaiting_rpa', 'processing']),
|
||||
@@ -357,7 +357,7 @@ def report_test_export(payload: dict[str, Any]) -> dict[str, Any]:
|
||||
db.session.commit()
|
||||
return _payload(run)
|
||||
# Windows Worker 回传 C:\HxopsRpa...\inventory_drop\file.xlsx;Linux 后端必须映射到
|
||||
# SHIPPING_NOTICE_RPA_SHARED_INVENTORY_DROP_DIR 下同名文件,否则 Path(windows).is_file() 恒假。
|
||||
# FREIGHT_RPA_SHARED_INVENTORY_DROP_DIR 下同名文件,否则 Path(windows).is_file() 恒假。
|
||||
raw_file_path = str(payload.get('file_path') or '').strip()
|
||||
path: Path | None = None
|
||||
from app.services.shipping_notice.rpa import inventory_drop_dir
|
||||
|
||||
@@ -56,11 +56,11 @@ def callback_quarantine_dir() -> Path | None:
|
||||
|
||||
|
||||
def callback_cleanup_max_attempts() -> int:
|
||||
"""cleanup job 最大重试次数(SHIPPING_NOTICE_RPA_CALLBACK_CLEANUP_MAX_ATTEMPTS)。"""
|
||||
"""cleanup job 最大重试次数(FREIGHT_RPA_CALLBACK_CLEANUP_MAX_ATTEMPTS)。"""
|
||||
try:
|
||||
return max(
|
||||
1,
|
||||
int(current_app.config.get("SHIPPING_NOTICE_RPA_CALLBACK_CLEANUP_MAX_ATTEMPTS") or _DEFAULT_MAX_CLEANUP_ATTEMPTS),
|
||||
int(current_app.config.get("FREIGHT_RPA_CALLBACK_CLEANUP_MAX_ATTEMPTS") or _DEFAULT_MAX_CLEANUP_ATTEMPTS),
|
||||
)
|
||||
except (TypeError, ValueError):
|
||||
return _DEFAULT_MAX_CLEANUP_ATTEMPTS
|
||||
|
||||
@@ -117,7 +117,7 @@ def _requeue_external_wait_job(task_no: str, *, job: Job | None = None) -> None:
|
||||
scheduled_at = next_inventory_rpa_recheck_at(task)
|
||||
if scheduled_at is None:
|
||||
recheck_seconds = max(
|
||||
float(current_app.config.get('SHIPPING_NOTICE_RPA_WAIT_RECHECK_SECONDS', 10) or 10),
|
||||
float(current_app.config.get('FREIGHT_RPA_WAIT_RECHECK_SECONDS', 10) or 10),
|
||||
1,
|
||||
)
|
||||
scheduled_at = datetime.utcnow() + timedelta(seconds=recheck_seconds)
|
||||
|
||||
@@ -26,7 +26,7 @@ from app.services.shipping_notice.audit_service import append_shipping_audit_eve
|
||||
|
||||
def _read_receipt_callback_file(file_path: str) -> bytes:
|
||||
"""只读取收料专用 drop 根内的 xlsx,拒绝 callback 任意本机文件读取。"""
|
||||
configured_root = str(current_app.config.get('SHIPPING_NOTICE_RPA_SHARED_RECEIPT_DROP_DIR') or '').strip()
|
||||
configured_root = str(current_app.config.get('FREIGHT_RPA_SHARED_RECEIPT_DROP_DIR') or '').strip()
|
||||
if not configured_root:
|
||||
raise ValidationError('receipt callback file root is unavailable', code='SHIPPING.RECEIPT_CALLBACK_FILE_INVALID')
|
||||
root = Path(configured_root).resolve()
|
||||
|
||||
@@ -14,7 +14,7 @@ from flask import current_app
|
||||
|
||||
def receipt_trigger_dir() -> Path | None:
|
||||
"""返回收料专用 trigger 目录;绝不回落到库存 trigger 目录。"""
|
||||
value = str(current_app.config.get('SHIPPING_NOTICE_RPA_SHARED_RECEIPT_TRIGGER_DIR') or '').strip()
|
||||
value = str(current_app.config.get('FREIGHT_RPA_SHARED_RECEIPT_TRIGGER_DIR') or '').strip()
|
||||
return Path(value) if value else None
|
||||
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ def rpa_runtime_mode(runtime: dict[str, Any] | None = None) -> dict[str, str | b
|
||||
mode = str(runtime.get("mode") or runtime.get("rpa_mode") or "").strip().lower()
|
||||
if mode in {"browser", "mock"}:
|
||||
return _runtime_summary(mode)
|
||||
raw = str(current_app.config.get("SHIPPING_NOTICE_RPA_WORKER_MOCK", "false") or "false").strip().lower()
|
||||
raw = str(current_app.config.get("FREIGHT_RPA_WORKER_MOCK", "false") or "false").strip().lower()
|
||||
return _runtime_summary("mock" if raw in {"1", "true", "yes", "on"} else "browser")
|
||||
|
||||
|
||||
@@ -49,8 +49,8 @@ def _path(key: str) -> Path | None:
|
||||
|
||||
|
||||
def inventory_drop_dir() -> Path | None:
|
||||
"""RPA 库存 Excel 落盘目录(SHIPPING_NOTICE_RPA_SHARED_INVENTORY_DROP_DIR)。"""
|
||||
return _path("SHIPPING_NOTICE_RPA_SHARED_INVENTORY_DROP_DIR")
|
||||
"""RPA 库存 Excel 落盘目录(FREIGHT_RPA_SHARED_INVENTORY_DROP_DIR)。"""
|
||||
return _path("FREIGHT_RPA_SHARED_INVENTORY_DROP_DIR")
|
||||
|
||||
|
||||
def inventory_processed_dir() -> Path | None:
|
||||
@@ -63,7 +63,7 @@ def inventory_processed_dir() -> Path | None:
|
||||
|
||||
def inventory_trigger_dir() -> Path | None:
|
||||
"""RPA 库存导出触发 JSON 目录。"""
|
||||
return _path("SHIPPING_NOTICE_RPA_SHARED_INVENTORY_TRIGGER_DIR")
|
||||
return _path("FREIGHT_RPA_SHARED_INVENTORY_TRIGGER_DIR")
|
||||
|
||||
|
||||
def _write_trigger_json_atomic(path: Path, body: dict[str, Any]) -> None:
|
||||
@@ -82,12 +82,12 @@ def _write_trigger_json_atomic(path: Path, body: dict[str, Any]) -> None:
|
||||
|
||||
def upload_queue_dir() -> Path | None:
|
||||
"""货代上传 Excel 队列目录(RPA 从此处读取待上传文件)。"""
|
||||
return _path("SHIPPING_NOTICE_RPA_SHARED_UPLOAD_QUEUE_DIR")
|
||||
return _path("FREIGHT_RPA_SHARED_UPLOAD_QUEUE_DIR")
|
||||
|
||||
|
||||
def upload_trigger_dir() -> Path | None:
|
||||
"""RPA 货代上传触发 JSON 目录。"""
|
||||
return _path("SHIPPING_NOTICE_RPA_SHARED_UPLOAD_TRIGGER_DIR")
|
||||
return _path("FREIGHT_RPA_SHARED_UPLOAD_TRIGGER_DIR")
|
||||
|
||||
|
||||
def write_inventory_export_trigger(task_no: str, payload: dict[str, Any] | None = None) -> str | None:
|
||||
|
||||
@@ -86,8 +86,8 @@ def upload_rpa_attempts(task: ShippingNotice | None) -> int:
|
||||
|
||||
|
||||
def max_rpa_upload_attempts() -> int:
|
||||
"""RPA 货代上传最大重试次数(环境变量 SHIPPING_NOTICE_RPA_UPLOAD_MAX_ATTEMPTS)。"""
|
||||
value = os.getenv("SHIPPING_NOTICE_RPA_UPLOAD_MAX_ATTEMPTS")
|
||||
"""RPA 货代上传最大重试次数(环境变量 FREIGHT_RPA_UPLOAD_MAX_ATTEMPTS)。"""
|
||||
value = os.getenv("FREIGHT_RPA_UPLOAD_MAX_ATTEMPTS")
|
||||
if value is None or not str(value).strip():
|
||||
return DEFAULT_RPA_UPLOAD_MAX_ATTEMPTS
|
||||
try:
|
||||
|
||||
@@ -39,6 +39,7 @@ _MEMORY_LOCK = threading.Lock()
|
||||
|
||||
_REASON_USER_HINTS: dict[str, str] = {
|
||||
"no_worker_heartbeat": "未收到任何 Worker 心跳",
|
||||
"heartbeat_store_process_local": "未配置 REDIS_URL(或 Redis 不可达),心跳存储为本进程内存,跨进程不可见;请配置 REDIS_URL 或设 FREIGHT_RPA_WORKER_HEARTBEAT_REQUIRED=false 跳过心跳检查",
|
||||
"heartbeat_storage_unavailable": "心跳存储不可用(Redis)",
|
||||
"trigger_dir_not_configured": "后端未配置 trigger 目录",
|
||||
"trigger_dir_not_accessible": "trigger 目录不存在或不可访问",
|
||||
@@ -48,7 +49,7 @@ _REASON_USER_HINTS: dict[str, str] = {
|
||||
"environment_mismatch": "Worker 环境与后端环境不一致",
|
||||
"missing_inventory_export_capability": "Worker 未声明 inventory_export 能力",
|
||||
"missing_freight_upload_capability": "Worker 未声明 freight_upload 能力",
|
||||
"credential_key_missing": "未配置 SHIPPING_NOTICE_RPA_CREDENTIAL_KEY",
|
||||
"credential_key_missing": "未配置 FREIGHT_RPA_CREDENTIAL_KEY",
|
||||
"upload_queue_dir_not_configured": "未配置货代上传队列目录",
|
||||
"upload_queue_dir_not_accessible": "货代上传队列目录不可访问",
|
||||
"callback_api_base_missing": "未配置 Worker 回调可达的 API 基址",
|
||||
@@ -91,9 +92,9 @@ def _config_str(key: str, default: str = "") -> str:
|
||||
def _heartbeat_ttl_seconds() -> int:
|
||||
raw = 90
|
||||
if current_app:
|
||||
raw = int(current_app.config.get("SHIPPING_NOTICE_RPA_WORKER_HEARTBEAT_TTL_SECONDS") or 90)
|
||||
raw = int(current_app.config.get("FREIGHT_RPA_WORKER_HEARTBEAT_TTL_SECONDS") or 90)
|
||||
else:
|
||||
raw = int(os.getenv("SHIPPING_NOTICE_RPA_WORKER_HEARTBEAT_TTL_SECONDS") or "90")
|
||||
raw = int(os.getenv("FREIGHT_RPA_WORKER_HEARTBEAT_TTL_SECONDS") or "90")
|
||||
return max(60, raw)
|
||||
|
||||
|
||||
@@ -101,16 +102,16 @@ def _heartbeat_check_required() -> bool:
|
||||
"""Mock RPA 或显式关闭时跳过 worker 心跳就绪检查。"""
|
||||
if rpa_runtime_mode().get("mock"):
|
||||
return False
|
||||
return _config_bool("SHIPPING_NOTICE_RPA_WORKER_HEARTBEAT_REQUIRED", True)
|
||||
return _config_bool("FREIGHT_RPA_WORKER_HEARTBEAT_REQUIRED", True)
|
||||
|
||||
|
||||
def _heartbeat_redis_required() -> bool:
|
||||
"""test/prod 默认要求 Redis;dev 仅显式开启时要求。"""
|
||||
explicit = os.getenv("SHIPPING_NOTICE_RPA_WORKER_HEARTBEAT_REQUIRE_REDIS")
|
||||
explicit = os.getenv("FREIGHT_RPA_WORKER_HEARTBEAT_REQUIRE_REDIS")
|
||||
if explicit is not None and str(explicit).strip() != "":
|
||||
return _config_bool("SHIPPING_NOTICE_RPA_WORKER_HEARTBEAT_REQUIRE_REDIS", False)
|
||||
return _config_bool("FREIGHT_RPA_WORKER_HEARTBEAT_REQUIRE_REDIS", False)
|
||||
if current_app:
|
||||
configured = current_app.config.get("SHIPPING_NOTICE_RPA_WORKER_HEARTBEAT_REQUIRE_REDIS")
|
||||
configured = current_app.config.get("FREIGHT_RPA_WORKER_HEARTBEAT_REQUIRE_REDIS")
|
||||
if configured is not None:
|
||||
return bool(configured)
|
||||
env_name = resolve_backend_rpa_environment()
|
||||
@@ -118,7 +119,7 @@ def _heartbeat_redis_required() -> bool:
|
||||
|
||||
|
||||
def _heartbeat_allow_memory_fallback() -> bool:
|
||||
return _config_bool("SHIPPING_NOTICE_RPA_WORKER_HEARTBEAT_ALLOW_MEMORY_FALLBACK", False)
|
||||
return _config_bool("FREIGHT_RPA_WORKER_HEARTBEAT_ALLOW_MEMORY_FALLBACK", False)
|
||||
|
||||
|
||||
def resolve_backend_rpa_environment() -> str:
|
||||
@@ -131,7 +132,7 @@ def resolve_backend_rpa_environment() -> str:
|
||||
|
||||
def shared_scope_id() -> str:
|
||||
"""共享 SMB 目录逻辑标识(如 hxops-rpa-test-data),用于跨平台路径对齐。"""
|
||||
explicit = _config_str("SHIPPING_NOTICE_RPA_SHARED_SCOPE_ID", "")
|
||||
explicit = _config_str("FREIGHT_RPA_SHARED_SCOPE_ID", "")
|
||||
if explicit:
|
||||
return explicit
|
||||
trigger_dir = inventory_trigger_dir()
|
||||
@@ -145,7 +146,7 @@ def shared_scope_id() -> str:
|
||||
|
||||
|
||||
def shared_sentinel_name() -> str:
|
||||
return _config_str("SHIPPING_NOTICE_RPA_SHARED_SENTINEL_NAME", ".hxops_rpa_shared_mount")
|
||||
return _config_str("FREIGHT_RPA_SHARED_SENTINEL_NAME", ".hxops_rpa_shared_mount")
|
||||
|
||||
|
||||
def _shared_mount_check_required() -> bool:
|
||||
@@ -208,9 +209,21 @@ def _memory_list_workers() -> list[dict[str, Any]]:
|
||||
|
||||
|
||||
def reset_rpa_worker_heartbeat_state_for_tests() -> None:
|
||||
"""单测隔离:清空进程内内存心跳缓存。"""
|
||||
"""单测隔离:清空进程内内存心跳缓存,并尽力清除 Redis 中的持久心跳记录。"""
|
||||
with _MEMORY_LOCK:
|
||||
_MEMORY_STORE.clear()
|
||||
try:
|
||||
client = _redis_client()
|
||||
if client is None:
|
||||
return
|
||||
worker_ids = list(client.smembers(_REDIS_INDEX_KEY) or [])
|
||||
stale_worker_keys = [f"{_REDIS_WORKER_KEY_PREFIX}{worker_id}" for worker_id in worker_ids]
|
||||
if stale_worker_keys:
|
||||
client.delete(*stale_worker_keys)
|
||||
client.delete(_REDIS_INDEX_KEY)
|
||||
except Exception:
|
||||
# 隔离辅助尽力而为:Redis 不可用时内存清空已足够单测运行。
|
||||
pass
|
||||
|
||||
|
||||
def _redis_store_worker(worker: dict[str, Any]) -> bool:
|
||||
@@ -517,6 +530,10 @@ def _check_rpa_worker_ready_for_capability(
|
||||
|
||||
if not workers and "heartbeat_storage_unavailable" not in reasons:
|
||||
reasons.append("no_worker_heartbeat")
|
||||
if _redis_client() is None and not eligible_workers:
|
||||
# 无 Redis 时心跳存储为本进程内存:写方(API 进程收 Worker POST)与读方(排程/告警进程)
|
||||
# 互不可见,本地排程必然命中 no_worker_heartbeat;追加原因码提示存储模式与本地测试姿势。
|
||||
reasons.append("heartbeat_store_process_local")
|
||||
|
||||
mount_block_tokens = {
|
||||
"trigger_dir_not_configured",
|
||||
@@ -583,7 +600,7 @@ def _freight_upload_config_reasons() -> list[str]:
|
||||
from app.services.shipping_notice.rpa import upload_queue_dir, upload_trigger_dir
|
||||
|
||||
reasons: list[str] = []
|
||||
credential_key = _config_str("SHIPPING_NOTICE_RPA_CREDENTIAL_KEY", "")
|
||||
credential_key = _config_str("FREIGHT_RPA_CREDENTIAL_KEY", "")
|
||||
if not credential_key:
|
||||
reasons.append("credential_key_missing")
|
||||
|
||||
|
||||
@@ -46,28 +46,28 @@ def _config_bool(key: str, default: bool) -> bool:
|
||||
def _alert_enabled() -> bool:
|
||||
if not _heartbeat_check_required():
|
||||
return False
|
||||
return _config_bool("SHIPPING_NOTICE_RPA_WORKER_ALERT_ENABLED", False)
|
||||
return _config_bool("FREIGHT_RPA_WORKER_ALERT_ENABLED", False)
|
||||
|
||||
|
||||
def _alert_cooldown_seconds() -> int:
|
||||
return max(300, int(current_app.config.get("SHIPPING_NOTICE_RPA_WORKER_ALERT_COOLDOWN_SECONDS") or 1800))
|
||||
return max(300, int(current_app.config.get("FREIGHT_RPA_WORKER_ALERT_COOLDOWN_SECONDS") or 1800))
|
||||
|
||||
|
||||
def _send_lock_seconds() -> int:
|
||||
"""企微发送中的短锁 TTL;发送失败过期后可重试,不进入长冷却。"""
|
||||
return max(60, int(current_app.config.get("SHIPPING_NOTICE_RPA_WORKER_ALERT_SEND_LOCK_SECONDS") or 120))
|
||||
return max(60, int(current_app.config.get("FREIGHT_RPA_WORKER_ALERT_SEND_LOCK_SECONDS") or 120))
|
||||
|
||||
|
||||
def _alert_fallback_admin_enabled() -> bool:
|
||||
return _config_bool("SHIPPING_NOTICE_RPA_WORKER_ALERT_FALLBACK_ADMIN", True)
|
||||
return _config_bool("FREIGHT_RPA_WORKER_ALERT_FALLBACK_ADMIN", True)
|
||||
|
||||
|
||||
def _alert_recipients() -> list[User]:
|
||||
"""
|
||||
解析告警接收人。
|
||||
核心逻辑:优先 SHIPPING_NOTICE_RPA_WORKER_ALERT_USERNAMES;未配置时可选回退已绑企微的 admin。
|
||||
核心逻辑:优先 FREIGHT_RPA_WORKER_ALERT_USERNAMES;未配置时可选回退已绑企微的 admin。
|
||||
"""
|
||||
raw = str(current_app.config.get("SHIPPING_NOTICE_RPA_WORKER_ALERT_USERNAMES") or "").strip()
|
||||
raw = str(current_app.config.get("FREIGHT_RPA_WORKER_ALERT_USERNAMES") or "").strip()
|
||||
names = [part.strip() for part in raw.split(",") if part.strip()] if raw else []
|
||||
if names:
|
||||
users = (
|
||||
@@ -105,7 +105,7 @@ def _log_recipient_gap_once() -> None:
|
||||
return
|
||||
_RECIPIENT_GAP_LOGGED = True
|
||||
logger.warning(
|
||||
"[rpa-heartbeat-alert] no wecom recipients: set SHIPPING_NOTICE_RPA_WORKER_ALERT_USERNAMES "
|
||||
"[rpa-heartbeat-alert] no wecom recipients: set FREIGHT_RPA_WORKER_ALERT_USERNAMES "
|
||||
"or bind wecom_userid for at least one admin (FALLBACK_ADMIN=true)"
|
||||
)
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ def shipping_recovery_tick() -> int:
|
||||
# 根据最新 Attempt/Gate 状态刷新按钮与阻断原因。
|
||||
inventory_timeout_seconds = max(int(getattr(
|
||||
current_app.config,
|
||||
'SHIPPING_NOTICE_RPA_INVENTORY_TIMEOUT_SECONDS',
|
||||
'FREIGHT_RPA_INVENTORY_TIMEOUT_SECONDS',
|
||||
900,
|
||||
) or 900), 1)
|
||||
inventory_scan_count = _scan_stale_inventory_attempts(
|
||||
|
||||
@@ -83,7 +83,7 @@ def auto_rpa_inventory_enabled() -> bool:
|
||||
|
||||
def rpa_inventory_timeout_seconds() -> int:
|
||||
"""RPA 库存导出等待超时秒数。"""
|
||||
return cfg_int("SHIPPING_NOTICE_RPA_INVENTORY_TIMEOUT_SECONDS", 900, min_value=5)
|
||||
return cfg_int("FREIGHT_RPA_INVENTORY_TIMEOUT_SECONDS", 900, min_value=5)
|
||||
|
||||
|
||||
def auto_mapping_allow_llm() -> bool:
|
||||
|
||||
Reference in new issue
Block a user