Backend: Rename PrismWorker to MetaWorker
Signed-off-by: Michael Mayer <michael@liquidbytes.net>
This commit is contained in:
parent
1c72f88e8c
commit
2a24bf293d
5 changed files with 29 additions and 29 deletions
|
@ -210,7 +210,7 @@ func (c *Config) Shutdown() {
|
|||
mutex.MainWorker.Cancel()
|
||||
mutex.ShareWorker.Cancel()
|
||||
mutex.SyncWorker.Cancel()
|
||||
mutex.PrismWorker.Cancel()
|
||||
mutex.MetaWorker.Cancel()
|
||||
|
||||
if err := c.CloseDb(); err != nil {
|
||||
log.Errorf("could not close database connection: %s", err)
|
||||
|
|
|
@ -9,10 +9,10 @@ var (
|
|||
MainWorker = Busy{}
|
||||
SyncWorker = Busy{}
|
||||
ShareWorker = Busy{}
|
||||
PrismWorker = Busy{}
|
||||
MetaWorker = Busy{}
|
||||
)
|
||||
|
||||
// WorkersBusy returns true if any worker is busy.
|
||||
func WorkersBusy() bool {
|
||||
return MainWorker.Busy() || SyncWorker.Busy() || ShareWorker.Busy() || PrismWorker.Busy()
|
||||
return MainWorker.Busy() || SyncWorker.Busy() || ShareWorker.Busy() || MetaWorker.Busy()
|
||||
}
|
||||
|
|
|
@ -12,47 +12,47 @@ import (
|
|||
"github.com/photoprism/photoprism/internal/query"
|
||||
)
|
||||
|
||||
// Prism represents a background maintenance worker.
|
||||
type Prism struct {
|
||||
// Meta represents a background metadata maintenance worker.
|
||||
type Meta struct {
|
||||
conf *config.Config
|
||||
}
|
||||
|
||||
// NewPrism returns a new background maintenance worker.
|
||||
func NewPrism(conf *config.Config) *Prism {
|
||||
return &Prism{conf: conf}
|
||||
// NewMeta returns a new background metadata maintenance worker.
|
||||
func NewMeta(conf *config.Config) *Meta {
|
||||
return &Meta{conf: conf}
|
||||
}
|
||||
|
||||
// logError logs an error message if err is not nil.
|
||||
func (worker *Prism) logError(err error) {
|
||||
func (worker *Meta) logError(err error) {
|
||||
if err != nil {
|
||||
log.Errorf("prism: %s", err.Error())
|
||||
log.Errorf("metadata: %s", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
// logWarn logs a warning message if err is not nil.
|
||||
func (worker *Prism) logWarn(err error) {
|
||||
func (worker *Meta) logWarn(err error) {
|
||||
if err != nil {
|
||||
log.Warnf("prism: %s", err.Error())
|
||||
log.Warnf("metadata: %s", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
// originalsPath returns the original media files path as string.
|
||||
func (worker *Prism) originalsPath() string {
|
||||
func (worker *Meta) originalsPath() string {
|
||||
return worker.conf.OriginalsPath()
|
||||
}
|
||||
|
||||
// Start starts the prism worker.
|
||||
func (worker *Prism) Start() (err error) {
|
||||
if err := mutex.PrismWorker.Start(); err != nil {
|
||||
// Start starts the metadata worker.
|
||||
func (worker *Meta) Start() (err error) {
|
||||
if err := mutex.MetaWorker.Start(); err != nil {
|
||||
worker.logWarn(err)
|
||||
return err
|
||||
}
|
||||
|
||||
defer func() {
|
||||
mutex.PrismWorker.Stop()
|
||||
mutex.MetaWorker.Stop()
|
||||
|
||||
if err := recover(); err != nil {
|
||||
log.Errorf("metadata: %s (prism worker panic)", err)
|
||||
log.Errorf("metadata: %s (worker panic)", err)
|
||||
}
|
||||
}()
|
||||
|
||||
|
@ -78,7 +78,7 @@ func (worker *Prism) Start() (err error) {
|
|||
}
|
||||
|
||||
for _, photo := range photos {
|
||||
if mutex.PrismWorker.Canceled() {
|
||||
if mutex.MetaWorker.Canceled() {
|
||||
return errors.New("metadata: check canceled")
|
||||
}
|
||||
|
||||
|
@ -96,7 +96,7 @@ func (worker *Prism) Start() (err error) {
|
|||
}
|
||||
}
|
||||
|
||||
if mutex.PrismWorker.Canceled() {
|
||||
if mutex.MetaWorker.Canceled() {
|
||||
return errors.New("metadata: check canceled")
|
||||
}
|
||||
|
|
@ -13,11 +13,11 @@ func TestPrism_Start(t *testing.T) {
|
|||
|
||||
t.Logf("database-dsn: %s", conf.DatabaseDsn())
|
||||
|
||||
worker := NewPrism(conf)
|
||||
worker := NewMeta(conf)
|
||||
|
||||
assert.IsType(t, &Prism{}, worker)
|
||||
assert.IsType(t, &Meta{}, worker)
|
||||
|
||||
if err := mutex.PrismWorker.Start(); err != nil {
|
||||
if err := mutex.MetaWorker.Start(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,7 @@ func TestPrism_Start(t *testing.T) {
|
|||
t.Fatal("error expected")
|
||||
}
|
||||
|
||||
mutex.PrismWorker.Stop()
|
||||
mutex.MetaWorker.Stop()
|
||||
|
||||
if err := worker.Start(); err != nil {
|
||||
t.Fatal(err)
|
|
@ -21,12 +21,12 @@ func Start(conf *config.Config) {
|
|||
case <-stop:
|
||||
log.Info("shutting down workers")
|
||||
ticker.Stop()
|
||||
mutex.PrismWorker.Cancel()
|
||||
mutex.MetaWorker.Cancel()
|
||||
mutex.ShareWorker.Cancel()
|
||||
mutex.SyncWorker.Cancel()
|
||||
return
|
||||
case <-ticker.C:
|
||||
StartPrism(conf)
|
||||
StartMeta(conf)
|
||||
StartShare(conf)
|
||||
StartSync(conf)
|
||||
}
|
||||
|
@ -39,11 +39,11 @@ func Stop() {
|
|||
stop <- true
|
||||
}
|
||||
|
||||
// StartPrism runs the prism worker once.
|
||||
func StartPrism(conf *config.Config) {
|
||||
// StartMeta runs the metadata worker once.
|
||||
func StartMeta(conf *config.Config) {
|
||||
if !mutex.WorkersBusy() {
|
||||
go func() {
|
||||
worker := NewPrism(conf)
|
||||
worker := NewMeta(conf)
|
||||
if err := worker.Start(); err != nil {
|
||||
log.Error(err)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue