Places: Refactor places update CLI command #1664

This commit is contained in:
Michael Mayer 2021-11-22 11:27:53 +01:00
parent 6ce109153b
commit 62257dec5d
2 changed files with 18 additions and 17 deletions

View file

@ -28,18 +28,6 @@ var PlacesCommand = cli.Command{
// placesUpdateAction fetches updated location data.
func placesUpdateAction(ctx *cli.Context) error {
start := time.Now()
confirmPrompt := promptui.Prompt{
Label: "Interrupting the update may result in inconsistent data. Proceed?",
IsConfirm: true,
}
// Abort?
if _, err := confirmPrompt.Run(); err != nil {
return nil
}
// Load config.
conf := config.NewConfig(ctx)
service.SetConfig(conf)
@ -53,6 +41,23 @@ func placesUpdateAction(ctx *cli.Context) error {
conf.InitDb()
if !conf.Sponsor() && !conf.Test() {
log.Errorf(config.MsgSponsorCommand)
return nil
}
confirmPrompt := promptui.Prompt{
Label: "Interrupting the update may result in inconsistent data. Proceed?",
IsConfirm: true,
}
// Abort?
if _, err := confirmPrompt.Run(); err != nil {
return nil
}
start := time.Now()
// Run places worker.
if w := service.Places(); w != nil {
_, err := w.Start()

View file

@ -36,14 +36,10 @@ func (w *Places) Start() (updated []string, err error) {
}
}()
// Check if a worker is already running.
if err := mutex.MainWorker.Start(); err != nil {
// A worker is already running.
log.Warnf("index: %s (update places)", err.Error())
return []string{}, err
} else if !w.conf.Sponsor() && !w.conf.Test() {
log.Errorf(config.MsgSponsorCommand)
log.Errorf(config.MsgFundingInfo)
return []string{}, err
}
defer mutex.MainWorker.Stop()