From 2a24bf293d57d7d116c4afade7c80369fa742ec4 Mon Sep 17 00:00:00 2001 From: Michael Mayer Date: Mon, 29 Jun 2020 13:35:38 +0200 Subject: [PATCH] Backend: Rename PrismWorker to MetaWorker Signed-off-by: Michael Mayer --- internal/config/config.go | 2 +- internal/mutex/mutex.go | 4 +-- internal/workers/{prism.go => meta.go} | 34 +++++++++---------- .../workers/{prism_test.go => meta_test.go} | 8 ++--- internal/workers/workers.go | 10 +++--- 5 files changed, 29 insertions(+), 29 deletions(-) rename internal/workers/{prism.go => meta.go} (71%) rename internal/workers/{prism_test.go => meta_test.go} (78%) diff --git a/internal/config/config.go b/internal/config/config.go index 70d2020fe..285cd0c7a 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -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) diff --git a/internal/mutex/mutex.go b/internal/mutex/mutex.go index f0ad894b9..e02f7af0c 100644 --- a/internal/mutex/mutex.go +++ b/internal/mutex/mutex.go @@ -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() } diff --git a/internal/workers/prism.go b/internal/workers/meta.go similarity index 71% rename from internal/workers/prism.go rename to internal/workers/meta.go index f46228d31..aeb9d5d2c 100644 --- a/internal/workers/prism.go +++ b/internal/workers/meta.go @@ -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") } diff --git a/internal/workers/prism_test.go b/internal/workers/meta_test.go similarity index 78% rename from internal/workers/prism_test.go rename to internal/workers/meta_test.go index 26c653ee6..4dd3d7144 100644 --- a/internal/workers/prism_test.go +++ b/internal/workers/meta_test.go @@ -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) diff --git a/internal/workers/workers.go b/internal/workers/workers.go index 55e100d32..215b33d16 100644 --- a/internal/workers/workers.go +++ b/internal/workers/workers.go @@ -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) }