mirror of
https://github.com/legop3/MultiRoombaRover.git
synced 2026-09-16 01:21:20 -04:00
ieuyryehj
This commit is contained in:
@@ -6,8 +6,6 @@ const path = require('path');
|
||||
|
||||
const CANONICAL_DATA_DIR = path.resolve(__dirname, '..', '..', 'data');
|
||||
const LEGACY_DATA_DIR = path.resolve(__dirname, '..', 'data');
|
||||
const CANONICAL_ROVER_SNAPSHOT_DIR = path.join(CANONICAL_DATA_DIR, 'rover-snapshots');
|
||||
const LEGACY_ROVER_SNAPSHOT_DIR = path.join(LEGACY_DATA_DIR, 'rover-snapshots');
|
||||
|
||||
function pathExists(target) {
|
||||
try {
|
||||
@@ -37,16 +35,7 @@ function resolveDataPath(fileName) {
|
||||
return canonicalPath;
|
||||
}
|
||||
|
||||
function resolveRoverSnapshotDir() {
|
||||
const configured = String(process.env.ROVER_SNAPSHOT_DIR || '').trim();
|
||||
if (configured) return path.resolve(configured);
|
||||
if (pathExists(CANONICAL_ROVER_SNAPSHOT_DIR)) return CANONICAL_ROVER_SNAPSHOT_DIR;
|
||||
if (pathExists(LEGACY_ROVER_SNAPSHOT_DIR)) return LEGACY_ROVER_SNAPSHOT_DIR;
|
||||
return '/var/lib/rover-snapshots';
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
resolveDataDir,
|
||||
resolveDataPath,
|
||||
resolveRoverSnapshotDir,
|
||||
};
|
||||
|
||||
@@ -7,9 +7,9 @@ const roverManager = require('../roverManager');
|
||||
const { getRoomCameras } = require('../roomCameraService');
|
||||
const { getRoomCameraState } = require('../roomCameraService');
|
||||
const { getReplayHealthSnapshot } = require('../replayEngineV2');
|
||||
const { resolveRoverSnapshotDir } = require('../../helpers/dataPaths');
|
||||
const { resolveDataDir } = require('../../helpers/dataPaths');
|
||||
|
||||
const ROVER_SNAPSHOT_DIR = resolveRoverSnapshotDir();
|
||||
const ROVER_SNAPSHOT_DIR = path.join(resolveDataDir(), 'rover-snapshots');
|
||||
const HEALTH_INTERVAL_MS = 5000;
|
||||
const ROOM_CAMERA_STALE_MS = 5000;
|
||||
const ROVER_SNAPSHOT_STALE_MS = 5000;
|
||||
|
||||
@@ -5,9 +5,9 @@ const EventEmitter = require('events');
|
||||
const fs = require('fs/promises');
|
||||
const path = require('path');
|
||||
const logger = require('../../globals/logger').child('roverSnapshot');
|
||||
const { resolveRoverSnapshotDir } = require('../../helpers/dataPaths');
|
||||
const { resolveDataDir } = require('../../helpers/dataPaths');
|
||||
|
||||
const SNAPSHOT_DIR = resolveRoverSnapshotDir();
|
||||
const SNAPSHOT_DIR = path.join(resolveDataDir(), 'rover-snapshots');
|
||||
const POLL_INTERVAL_MS = 300;
|
||||
const roverState = new Map();
|
||||
const events = new EventEmitter();
|
||||
@@ -25,15 +25,14 @@ function getSnapshotPath(id) {
|
||||
}
|
||||
|
||||
function createRoverSnapshotPoller({ roverManager }) {
|
||||
async function fetchSnapshot(id, options = {}) {
|
||||
const force = Boolean(options?.force);
|
||||
async function fetchSnapshot(id) {
|
||||
const state = roverState.get(id);
|
||||
if (state?.fetching) return;
|
||||
markState(id, { fetching: true });
|
||||
try {
|
||||
const filePath = getSnapshotPath(id);
|
||||
const stats = await fs.stat(filePath);
|
||||
if (!force && state?.mtimeMs && stats.mtimeMs <= state.mtimeMs) return;
|
||||
if (state?.mtimeMs && stats.mtimeMs <= state.mtimeMs) return;
|
||||
const buffer = await fs.readFile(filePath);
|
||||
const ts = stats.mtimeMs || Date.now();
|
||||
markState(id, { frame: buffer, ts, error: null, failures: 0, mtimeMs: stats.mtimeMs });
|
||||
@@ -93,7 +92,6 @@ function createRoverSnapshotPoller({ roverManager }) {
|
||||
return {
|
||||
startAll,
|
||||
stopAll,
|
||||
fetchSnapshotNow: fetchSnapshot,
|
||||
roverSnapshotEvents: events,
|
||||
getRoverSnapshotState,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user