mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-05 10:45:21 +03:00
Use single DB instance for all processes
This commit is contained in:
parent
f0c1b66b0f
commit
3fa70a550f
@ -175,6 +175,9 @@ class FrigateApp:
|
||||
router.run()
|
||||
|
||||
migrate_db.close()
|
||||
self.db = SqliteQueueDatabase(self.config.database.path)
|
||||
models = [Event, Recordings, Timeline]
|
||||
self.db.bind(models)
|
||||
|
||||
def init_go2rtc(self) -> None:
|
||||
for proc in psutil.process_iter(["pid", "name"]):
|
||||
@ -186,7 +189,7 @@ class FrigateApp:
|
||||
recording_process = mp.Process(
|
||||
target=manage_recordings,
|
||||
name="recording_manager",
|
||||
args=(self.config, self.recordings_info_queue, self.record_metrics),
|
||||
args=(self.config, self.db, self.recordings_info_queue, self.record_metrics),
|
||||
)
|
||||
recording_process.daemon = True
|
||||
self.recording_process = recording_process
|
||||
@ -194,13 +197,6 @@ class FrigateApp:
|
||||
self.processes["recording"] = recording_process.pid or 0
|
||||
logger.info(f"Recording process started: {recording_process.pid}")
|
||||
|
||||
def bind_database(self) -> None:
|
||||
"""Bind db to the main process."""
|
||||
# NOTE: all db accessing processes need to be created before the db can be bound to the main process
|
||||
self.db = SqliteQueueDatabase(self.config.database.path)
|
||||
models = [Event, Recordings, Timeline]
|
||||
self.db.bind(models)
|
||||
|
||||
def init_stats(self) -> None:
|
||||
self.stats_tracking = stats_init(
|
||||
self.config, self.camera_metrics, self.detectors, self.processes
|
||||
@ -431,7 +427,6 @@ class FrigateApp:
|
||||
self.init_onvif()
|
||||
self.init_recording_manager()
|
||||
self.init_go2rtc()
|
||||
self.bind_database()
|
||||
self.init_dispatcher()
|
||||
except Exception as e:
|
||||
print(e)
|
||||
|
||||
@ -22,6 +22,7 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
def manage_recordings(
|
||||
config: FrigateConfig,
|
||||
db: SqliteQueueDatabase,
|
||||
recordings_info_queue: mp.Queue,
|
||||
process_info: dict[str, RecordMetricsTypes],
|
||||
) -> None:
|
||||
@ -37,7 +38,6 @@ def manage_recordings(
|
||||
setproctitle("frigate.recording_manager")
|
||||
listen()
|
||||
|
||||
db = SqliteQueueDatabase(config.database.path)
|
||||
models = [Event, Recordings, Timeline]
|
||||
db.bind(models)
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user