mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-03 12:37:37 +03:00
Use singleton in other places as well
This commit is contained in:
parent
1f997357a9
commit
743e469795
7 changed files with 39 additions and 104 deletions
|
@ -3,6 +3,7 @@ package scheduler
|
|||
import (
|
||||
"context"
|
||||
|
||||
"github.com/navidrome/navidrome/utils/singleton"
|
||||
"github.com/robfig/cron/v3"
|
||||
)
|
||||
|
||||
|
@ -11,11 +12,14 @@ type Scheduler interface {
|
|||
Add(crontab string, cmd func()) error
|
||||
}
|
||||
|
||||
func New() Scheduler {
|
||||
c := cron.New(cron.WithLogger(&logger{}))
|
||||
return &scheduler{
|
||||
c: c,
|
||||
}
|
||||
func GetInstance() Scheduler {
|
||||
instance := singleton.Get(&scheduler{}, func() interface{} {
|
||||
c := cron.New(cron.WithLogger(&logger{}))
|
||||
return &scheduler{
|
||||
c: c,
|
||||
}
|
||||
})
|
||||
return instance.(*scheduler)
|
||||
}
|
||||
|
||||
type scheduler struct {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue