From 173c3172386eeae9c232ce1df6e321ed03fd99fe Mon Sep 17 00:00:00 2001 From: Jamie Banks Date: Wed, 17 Jun 2026 08:42:54 +0100 Subject: [PATCH 1/2] refactor: process files concurrently and add stability check before queueing while ignoring the binary output --- .gitignore | 3 ++- internal/watcher/watcher.go | 29 +++++++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index c59768b..3a07958 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -media/ \ No newline at end of file +media/ +goencode \ No newline at end of file diff --git a/internal/watcher/watcher.go b/internal/watcher/watcher.go index 4e1473d..7635598 100644 --- a/internal/watcher/watcher.go +++ b/internal/watcher/watcher.go @@ -138,7 +138,7 @@ func (m *Manager) processWorker() { case <-m.stopChan: return case path := <-m.processChan: - m.processFile(path) + go m.processFile(path) } } } @@ -151,7 +151,7 @@ func (m *Manager) handleEvent(filePath string) { t.Stop() } - m.timers[filePath] = time.AfterFunc(5*time.Second, func() { + m.timers[filePath] = time.AfterFunc(2*time.Minute, func() { m.timersMu.Lock() delete(m.timers, filePath) m.timersMu.Unlock() @@ -176,6 +176,31 @@ func (m *Manager) processFile(filePath string) { return } + // Wait until the file is fully copied and stable + var lastSize int64 = info.Size() + var lastModTime time.Time = info.ModTime() + var stableCount int + + for { + time.Sleep(5 * time.Second) + currentInfo, err := os.Stat(filePath) + if err != nil { + return // File was likely deleted during copying + } + + if currentInfo.Size() == lastSize && currentInfo.ModTime().Equal(lastModTime) { + stableCount++ + if stableCount >= 3 { // Stable for 15 seconds + break + } + } else { + stableCount = 0 + lastSize = currentInfo.Size() + lastModTime = currentInfo.ModTime() + } + } + + // Re-check after waiting alreadyInQueue, err := db.IsFileAlreadyProcessedOrQueued(filePath) if err != nil { log.Printf("Error checking DB for %s: %v", filePath, err) From ae869e7a2eef68e699e3bc31d12068b39bc1196b Mon Sep 17 00:00:00 2001 From: Jamie Banks Date: Wed, 17 Jun 2026 08:44:31 +0100 Subject: [PATCH 2/2] fix: trigger queue processing immediately after adding a new job --- internal/web/api.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/web/api.go b/internal/web/api.go index cafddb9..1d4c93c 100644 --- a/internal/web/api.go +++ b/internal/web/api.go @@ -165,5 +165,6 @@ func (s *Server) handleRequeueJob(w http.ResponseWriter, r *http.Request) { s.qm.NotifySSE("queue_updated", nil) s.qm.NotifySSE("job_added", nil) + s.qm.Trigger() w.WriteHeader(http.StatusOK) }