mirror of
https://github.com/photoprism/photoprism.git
synced 2025-12-12 00:34:13 +01:00
Move share & sync to workers package #225
Signed-off-by: Michael Mayer <michael@liquidbytes.net>
This commit is contained in:
53
internal/workers/workers.go
Normal file
53
internal/workers/workers.go
Normal file
@@ -0,0 +1,53 @@
|
||||
package workers
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/photoprism/photoprism/internal/config"
|
||||
"github.com/photoprism/photoprism/internal/event"
|
||||
"github.com/photoprism/photoprism/internal/mutex"
|
||||
)
|
||||
|
||||
var log = event.Log
|
||||
var stop = make(chan bool, 1)
|
||||
|
||||
func Start(conf *config.Config) {
|
||||
ticker := time.NewTicker(5 * time.Minute) // TODO
|
||||
|
||||
go func() {
|
||||
for {
|
||||
select {
|
||||
case <-stop:
|
||||
log.Info("shutting down service workers")
|
||||
ticker.Stop()
|
||||
mutex.Share.Cancel()
|
||||
mutex.Sync.Cancel()
|
||||
return
|
||||
case <-ticker.C:
|
||||
if !mutex.Share.Busy() {
|
||||
go func() {
|
||||
// Start
|
||||
s := NewShare(conf)
|
||||
if err := s.Start(); err != nil {
|
||||
log.Error(err)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
if !mutex.Sync.Busy() {
|
||||
go func() {
|
||||
// Start
|
||||
s := NewSync(conf)
|
||||
if err := s.Start(); err != nil {
|
||||
log.Error(err)
|
||||
}
|
||||
}()
|
||||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
func Stop() {
|
||||
stop <- true
|
||||
}
|
||||
Reference in New Issue
Block a user