Move share & sync to workers package #225

Signed-off-by: Michael Mayer <michael@liquidbytes.net>
This commit is contained in:
Michael Mayer 2020-04-06 09:41:42 +02:00
parent aa220a06fe
commit ae5b6b759e
4 changed files with 20 additions and 12 deletions

View file

@ -10,9 +10,9 @@ import (
"time" "time"
"github.com/photoprism/photoprism/internal/config" "github.com/photoprism/photoprism/internal/config"
"github.com/photoprism/photoprism/internal/photoprism"
"github.com/photoprism/photoprism/internal/server" "github.com/photoprism/photoprism/internal/server"
"github.com/photoprism/photoprism/internal/service" "github.com/photoprism/photoprism/internal/service"
"github.com/photoprism/photoprism/internal/workers"
"github.com/photoprism/photoprism/pkg/fs" "github.com/photoprism/photoprism/pkg/fs"
"github.com/sevlyar/go-daemon" "github.com/sevlyar/go-daemon"
"github.com/urfave/cli" "github.com/urfave/cli"
@ -118,15 +118,18 @@ func startAction(ctx *cli.Context) error {
// start web server // start web server
go server.Start(cctx, conf) go server.Start(cctx, conf)
// start share & sync service workers // start share & sync workers
stop := photoprism.ServiceWorkers(conf) workers.Start(conf)
// set up proper shutdown of daemon and web server // set up proper shutdown of daemon and web server
quit := make(chan os.Signal) quit := make(chan os.Signal)
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM) signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
<-quit <-quit
stop <- true
// stop share & sync workers
workers.Stop()
log.Info("shutting down...") log.Info("shutting down...")
conf.Shutdown() conf.Shutdown()
cancel() cancel()

View file

@ -1,4 +1,4 @@
package photoprism package workers
import ( import (
"fmt" "fmt"

View file

@ -1,4 +1,4 @@
package photoprism package workers
import ( import (
"fmt" "fmt"

View file

@ -1,15 +1,18 @@
package photoprism package workers
import ( import (
"time" "time"
"github.com/photoprism/photoprism/internal/config" "github.com/photoprism/photoprism/internal/config"
"github.com/photoprism/photoprism/internal/event"
"github.com/photoprism/photoprism/internal/mutex" "github.com/photoprism/photoprism/internal/mutex"
) )
func ServiceWorkers(conf *config.Config) chan bool { var log = event.Log
ticker := time.NewTicker(1 * time.Minute) // TODO var stop = make(chan bool, 1)
stop := make(chan bool, 1)
func Start(conf *config.Config) {
ticker := time.NewTicker(5 * time.Minute) // TODO
go func() { go func() {
for { for {
@ -43,6 +46,8 @@ func ServiceWorkers(conf *config.Config) chan bool {
} }
} }
}() }()
}
return stop
func Stop() {
stop <- true
} }