feat: enable full AI automation and safe startup updates

This commit is contained in:
chenmingxuan committed 2026-09-22 23:50:03 +08:00
1 parent 2ddec53954
commit 7b1a0755e2
62 files changed
+3123 -240

No files matched your search

@@ -466,6 +466,12 @@ class TaskQueueService:
"""Mark the task as running and announce the launch to subscribers."""
task_item["status"] = "running"
task_item["start_time"] = time.time()
from apps.admin_console.services.automation_store import store
job = store.job(str(sess_id)) if sess_id else None
if job:
job.update(status="running", started_at=time.time())
store.save_job(job)
# A fresh launch clears a stale stop request left over for this run
# key from a previous task. Manual stops are tracked per run in
@@ -559,6 +565,12 @@ class TaskQueueService:
if device_serial:
cmd.extend(["--device-serial", str(device_serial)])
env["ADB_DEVICE_SERIAL"] = str(device_serial)
from apps.admin_console.services.automation_store import store
from artemis.config import TRACES_PATH
job = store.job(str(sess_id)) if sess_id else None
if job:
env["RESULTS_OUTPUT_PATH"] = str(TRACES_PATH / str(sess_id) / "result.json")
return cmd, env
@classmethod
@@ -768,6 +780,11 @@ class TaskQueueService:
manual_stop: bool,
) -> None:
"""Broadcast session_ended and dispatch the external completion notification."""
from apps.admin_console.services.automation_store import store
from apps.admin_console.services.automation_service import spawn, on_terminal
if sess_id and store.job(str(sess_id)):
spawn(on_terminal(task_item, new_status))
state.active_connections.pop(sess_id, None)
cls._broadcast_event(
"session_ended",
@@ -938,7 +955,7 @@ class TaskQueueService:
}
# 2. Debounce duplicate rapid submissions (e.g. UI double-click or network retry within 1s)
if len(goals) == 1:
if len(goals) == 1 and not session_id:
first_goal = goals[0]
recent_duplicate = next(
(
@@ -1212,10 +1229,19 @@ class TaskQueueService:
@classmethod
def _stop_all_tasks(cls) -> bool:
"""Terminate all active device owners and clear pending queue submissions."""
from apps.admin_console.services.automation_store import store
from apps.admin_console.services.automation_service import on_terminal, spawn
for batch in store.records("batch"):
if batch["status"] == "running":
batch.update(status="paused", reason="已停止全部任务,等待手动继续")
store.put("batch", batch["id"], batch)
# 1. Cancel local queue reservations
for item in state.queue_items:
if isinstance(item, dict) and item.get("status") != "running":
DeviceExecutionLock.cancel_reservation(item.get("queue_ticket"))
if store.job(str(item.get("session_id"))):
spawn(on_terminal(item, "cancelled"))
state.clear_queue()
# 2. Terminate all active owners across all devices
@@ -1534,6 +1560,12 @@ class TaskQueueService:
),
None,
)
if stopped_item and stopped_item.get("status") != "running":
from apps.admin_console.services.automation_store import store
from apps.admin_console.services.automation_service import on_terminal, spawn
if store.job(str(stopped_session_id)):
spawn(on_terminal(stopped_item, "cancelled"))
if stopped_item and not reservation_cancelled:
DeviceExecutionLock.cancel_reservation(stopped_item.get("queue_ticket"))
state.queue_items = [