feat: make watchdog itself configurable
This commit is contained in:
@@ -1,10 +1,9 @@
|
||||
package database
|
||||
|
||||
import (
|
||||
"eden-server/internal/utility"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"orbits-server/internal/utility"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
@@ -77,7 +76,7 @@ func watchdog(env utility.Environment, db *gorm.DB) {
|
||||
case "sync":
|
||||
readerStream, err := os.Open(fp)
|
||||
if err != nil {
|
||||
|
||||
slog.Error("failed to a reader stream")
|
||||
}
|
||||
defer readerStream.Close()
|
||||
|
||||
@@ -86,8 +85,6 @@ func watchdog(env utility.Environment, db *gorm.DB) {
|
||||
slog.Error("failed to enroll local file into the database", "error", err)
|
||||
}
|
||||
|
||||
fmt.Println(fileData)
|
||||
|
||||
if err := RegisterFile(db, fileData); err != nil {
|
||||
if errors.Is(err, gorm.ErrDuplicatedKey) {
|
||||
slog.Debug("discarding file since its a duplicate", "error", err)
|
||||
@@ -96,6 +93,8 @@ func watchdog(env utility.Environment, db *gorm.DB) {
|
||||
}
|
||||
}
|
||||
|
||||
// to fully finalize the enrollment process, we rename the locally inserted file to a unique filename
|
||||
// this is to make all files comply, wether uploaded via the api or locally inserted with the filesystem
|
||||
if err := os.Rename(fp, fileData.FilePath); err != nil {
|
||||
slog.Error("failed to move the locally inserted file", "error", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user