feat: add locally syncing and watchdog
This commit is contained in:
@@ -2,7 +2,6 @@ package database
|
||||
|
||||
import (
|
||||
"eden-server/internal/utility"
|
||||
"log/slog"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
@@ -24,7 +23,6 @@ func KickoffDatabase(workDir string) (*gorm.DB, error) {
|
||||
}
|
||||
|
||||
// try to use GORM automigrate if the schema changes
|
||||
slog.Info("performing migration")
|
||||
if err := db.AutoMigrate(
|
||||
&State{},
|
||||
&Device{},
|
||||
@@ -36,7 +34,7 @@ func KickoffDatabase(workDir string) (*gorm.DB, error) {
|
||||
// create the first row if it does not exist yet
|
||||
if err := db.FirstOrCreate(&State{}, State{
|
||||
ID: 0,
|
||||
MediaType: "unspecified",
|
||||
MediaType: Unspecified,
|
||||
}).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -45,23 +43,12 @@ func KickoffDatabase(workDir string) (*gorm.DB, error) {
|
||||
}
|
||||
|
||||
func KickoffDatabaseWatchdog(env utility.Environment, db *gorm.DB) {
|
||||
timeInterval := time.Second * time.Duration(env.WatchInterval)
|
||||
timeInterval := time.Second * time.Duration(env.WatchdogInterval)
|
||||
ticker := time.NewTicker(timeInterval)
|
||||
|
||||
go func() {
|
||||
defer ticker.Stop()
|
||||
|
||||
/*
|
||||
// Possible future mechanism to stop the watchdog
|
||||
// must be inside a non-conditional for loop
|
||||
select {
|
||||
case <-ticker.C: // ticker event
|
||||
watchdog(env.DataDirectory, db)
|
||||
case <-watchdogStop:
|
||||
return
|
||||
}
|
||||
*/
|
||||
|
||||
// run the watchdog function once to see if all is well.
|
||||
watchdog(env, db)
|
||||
// then defer to a decoupled/disowned golang goroutine
|
||||
|
||||
Reference in New Issue
Block a user