Files
HSAP/scripts/worker.py
Chengfang Lu 7c43b44c57 feat: initial HSAP platform
Huaxu Sentinel Active Safety Platform with embedded algorithm code,
Docker Compose setup, and vendored dataset scaffolds for clone-and-run.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-25 16:59:59 +08:00

44 lines
1.1 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env python3
"""Job Worker从 Redis 队列取任务并执行GPU/训练机可单独跑此脚本)。"""
from __future__ import annotations
import signal
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT / "platform"))
from as_platform.config import JOB_EXECUTOR, JOB_QUEUE_KEY, REDIS_URL
from as_platform.jobs.queue import _run_job
from as_platform.redis.bus import ping_redis, pop_job
_running = True
def _stop(*_):
global _running
_running = False
def main() -> None:
if JOB_EXECUTOR != "worker":
print(f"AS_JOB_EXECUTOR={JOB_EXECUTOR}worker 脚本建议设为 worker", file=sys.stderr)
if not ping_redis():
print(f"Redis 不可用: {REDIS_URL}", file=sys.stderr)
sys.exit(1)
signal.signal(signal.SIGINT, _stop)
signal.signal(signal.SIGTERM, _stop)
print(f"Worker 监听队列 {JOB_QUEUE_KEY}")
while _running:
job_id = pop_job(timeout=3)
if job_id:
print(f"执行 Job {job_id}")
_run_job(job_id)
if __name__ == "__main__":
main()