mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-07-05 19:41:15 +03:00
Compare commits
No commits in common. "892901b4884c3b25e1ddd027ee12169ddf43e665" and "6e03dc6fffd282ea72fa27812eac0268d988b5b5" have entirely different histories.
892901b488
...
6e03dc6fff
@ -9,7 +9,6 @@ import logging
|
||||
import os
|
||||
import shutil
|
||||
import threading
|
||||
import time
|
||||
|
||||
from ruamel.yaml import YAML
|
||||
|
||||
@ -26,15 +25,7 @@ from frigate.const import (
|
||||
REPLAY_DIR,
|
||||
THUMB_DIR,
|
||||
)
|
||||
from frigate.jobs.debug_replay import (
|
||||
JOB_TYPE as DEBUG_REPLAY_JOB_TYPE,
|
||||
)
|
||||
from frigate.jobs.debug_replay import (
|
||||
cancel_debug_replay_job,
|
||||
wait_for_runner,
|
||||
)
|
||||
from frigate.jobs.export import JobStatePublisher
|
||||
from frigate.types import JobStatusTypesEnum
|
||||
from frigate.jobs.debug_replay import cancel_debug_replay_job, wait_for_runner
|
||||
from frigate.util.camera_cleanup import cleanup_camera_db, cleanup_camera_files
|
||||
from frigate.util.config import find_config_file
|
||||
|
||||
@ -58,7 +49,6 @@ class DebugReplayManager:
|
||||
self.clip_path: str | None = None
|
||||
self.start_ts: float | None = None
|
||||
self.end_ts: float | None = None
|
||||
self._job_state_publisher = JobStatePublisher()
|
||||
|
||||
@property
|
||||
def active(self) -> bool:
|
||||
@ -160,7 +150,6 @@ class DebugReplayManager:
|
||||
return
|
||||
|
||||
replay_name = self.replay_camera_name
|
||||
source_camera = self.source_camera
|
||||
|
||||
# Only publish remove if the camera was actually added to the live
|
||||
# config (i.e. the runner reached the starting_camera phase).
|
||||
@ -174,21 +163,6 @@ class DebugReplayManager:
|
||||
self._cleanup_db(replay_name)
|
||||
self._cleanup_files(replay_name)
|
||||
|
||||
self._job_state_publisher.publish(
|
||||
{
|
||||
"id": "stopped",
|
||||
"job_type": DEBUG_REPLAY_JOB_TYPE,
|
||||
"status": JobStatusTypesEnum.cancelled,
|
||||
"start_time": None,
|
||||
"end_time": time.time(),
|
||||
"error_message": None,
|
||||
"results": {
|
||||
"source_camera": source_camera,
|
||||
"replay_camera_name": replay_name,
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
self._clear_locked()
|
||||
|
||||
logger.info("Debug replay stopped and cleaned up: %s", replay_name)
|
||||
|
||||
@ -71,14 +71,6 @@ class TestDebugReplayManagerSession(unittest.TestCase):
|
||||
|
||||
|
||||
class TestDebugReplayManagerStop(unittest.TestCase):
|
||||
def setUp(self) -> None:
|
||||
# stop() publishes a terminal job_state via a real JobStatePublisher,
|
||||
# which opens a ZMQ REQ socket and blocks on REP. No dispatcher runs
|
||||
# in unit tests, so substitute a no-op publisher.
|
||||
patcher = patch("frigate.debug_replay.JobStatePublisher")
|
||||
patcher.start()
|
||||
self.addCleanup(patcher.stop)
|
||||
|
||||
def test_stop_when_inactive_is_a_noop(self) -> None:
|
||||
from frigate.debug_replay import DebugReplayManager
|
||||
|
||||
|
||||
@ -10,21 +10,15 @@ export function WsProvider({ children }: { children: ReactNode }) {
|
||||
const reconnectTimer = useRef<ReturnType<typeof setTimeout> | null>(null);
|
||||
const reconnectAttempt = useRef(0);
|
||||
const unmounted = useRef(false);
|
||||
const pendingSends = useRef<Map<string, unknown>>(new Map());
|
||||
|
||||
const sendJsonMessage = useCallback((msg: unknown) => {
|
||||
if (wsRef.current?.readyState === WebSocket.OPEN) {
|
||||
wsRef.current.send(JSON.stringify(msg));
|
||||
} else if (msg && typeof msg === "object" && "topic" in msg) {
|
||||
// Sends issued before the socket reaches OPEN (or during a reconnect
|
||||
// window) are buffered here and flushed in onopen
|
||||
pendingSends.current.set(String((msg as { topic: unknown }).topic), msg);
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
unmounted.current = false;
|
||||
const queue = pendingSends.current;
|
||||
|
||||
function connect() {
|
||||
if (unmounted.current) return;
|
||||
@ -37,10 +31,6 @@ export function WsProvider({ children }: { children: ReactNode }) {
|
||||
ws.send(
|
||||
JSON.stringify({ topic: "onConnect", message: "", retain: false }),
|
||||
);
|
||||
for (const queued of queue.values()) {
|
||||
ws.send(JSON.stringify(queued));
|
||||
}
|
||||
queue.clear();
|
||||
};
|
||||
|
||||
ws.onmessage = (event: MessageEvent) => {
|
||||
@ -74,7 +64,6 @@ export function WsProvider({ children }: { children: ReactNode }) {
|
||||
ws.onerror = null;
|
||||
ws.close();
|
||||
}
|
||||
queue.clear();
|
||||
resetWsStore();
|
||||
};
|
||||
}, [wsUrl]);
|
||||
|
||||
@ -10,7 +10,7 @@ import useSWR from "swr";
|
||||
import useDeepMemo from "./use-deep-memo";
|
||||
import { capitalizeAll, capitalizeFirstLetter } from "@/utils/stringUtil";
|
||||
import { isReplayCamera } from "@/utils/cameraUtil";
|
||||
import { useFrigateStats, useJobStatus } from "@/api/ws";
|
||||
import { useFrigateStats } from "@/api/ws";
|
||||
import { useIsAdmin } from "./use-is-admin";
|
||||
|
||||
import { useTranslation } from "react-i18next";
|
||||
@ -19,15 +19,11 @@ export default function useStats(stats: FrigateStats | undefined) {
|
||||
const { t } = useTranslation(["views/system"]);
|
||||
const { data: config } = useSWR<FrigateConfig>("config");
|
||||
const isAdmin = useIsAdmin();
|
||||
|
||||
// Pass isAdmin as revalidateOnFocus so non-admins never send the jobState snapshot pull
|
||||
const { payload: replayJob } = useJobStatus("debug_replay", isAdmin);
|
||||
const replayActive = Boolean(
|
||||
isAdmin &&
|
||||
replayJob &&
|
||||
(replayJob.status === "queued" ||
|
||||
replayJob.status === "running" ||
|
||||
replayJob.status === "success"),
|
||||
const { data: debugReplayStatus } = useSWR(
|
||||
isAdmin ? "debug_replay/status" : null,
|
||||
{
|
||||
revalidateOnFocus: false,
|
||||
},
|
||||
);
|
||||
|
||||
const memoizedStats = useDeepMemo(stats);
|
||||
@ -144,7 +140,7 @@ export default function useStats(stats: FrigateStats | undefined) {
|
||||
});
|
||||
|
||||
// Add message if debug replay is active
|
||||
if (replayActive) {
|
||||
if (debugReplayStatus?.active) {
|
||||
problems.push({
|
||||
text: t("stats.debugReplayActive", {
|
||||
defaultValue: "Debug replay session is active",
|
||||
@ -155,7 +151,7 @@ export default function useStats(stats: FrigateStats | undefined) {
|
||||
}
|
||||
|
||||
return problems;
|
||||
}, [config, memoizedStats, t, replayActive]);
|
||||
}, [config, memoizedStats, t, debugReplayStatus]);
|
||||
|
||||
return { potentialProblems };
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user