Places: Refactor places update CLI command #1664
This commit is contained in:
parent
6ce109153b
commit
62257dec5d
2 changed files with 18 additions and 17 deletions
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue