Skip to content

Commit

Permalink
fix shutdown when initial client retrieval fails
Browse files Browse the repository at this point in the history
  • Loading branch information
Spiritreader committed May 29, 2022
1 parent d3b56b4 commit 63c0b0d
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,13 @@ func runService(ctx context.Context, wg *sync.WaitGroup, cancel context.CancelFu
dataStore := db.Get()
sleepTime = 5

// initial client retrieval must succeed
client, err := dataStore.GetClientForMachine()
if err != nil {
_ = glg.Errorf("could not retrieve client data for machine, shutting down service")
wg.Done()
apiChan <- "stop"
cancel()
return
}

Expand All @@ -144,6 +148,7 @@ func runService(ctx context.Context, wg *sync.WaitGroup, cancel context.CancelFu
if err != nil {
_ = glg.Info("signed in %s", client.Name)
}

MainLoop:
for {
// check if client is allowed to run
Expand All @@ -170,7 +175,7 @@ MainLoop:
_, err = dataStore.DeleteJob(job.ID.Hex())
worker.ProcessJob(dataStore, client, job, resumeChan)
if err != nil {
_ = glg.Failf("couldn't delete job, program has to pause to prevent endless loop")
_ = glg.Failf("couldn't delete job, program has to pause to prevent it from retaking the job")
state.Paused = true
}
}
Expand All @@ -197,7 +202,7 @@ MainLoop:
}

// refresh client after sleeping time to ensure settings are updated properly
client, err := dataStore.GetClientForMachine()
client, err = dataStore.GetClientForMachine()
if err != nil {
_ = glg.Warnf("could not refresh client %s, using cached data", client.Name)
}
Expand Down

0 comments on commit 63c0b0d

Please sign in to comment.