Skip to content

Commit 63c0b0d

Browse files
committed
fix shutdown when initial client retrieval fails
1 parent d3b56b4 commit 63c0b0d

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

app.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,13 @@ func runService(ctx context.Context, wg *sync.WaitGroup, cancel context.CancelFu
133133
dataStore := db.Get()
134134
sleepTime = 5
135135

136+
// initial client retrieval must succeed
136137
client, err := dataStore.GetClientForMachine()
137138
if err != nil {
139+
_ = glg.Errorf("could not retrieve client data for machine, shutting down service")
138140
wg.Done()
141+
apiChan <- "stop"
142+
cancel()
139143
return
140144
}
141145

@@ -144,6 +148,7 @@ func runService(ctx context.Context, wg *sync.WaitGroup, cancel context.CancelFu
144148
if err != nil {
145149
_ = glg.Info("signed in %s", client.Name)
146150
}
151+
147152
MainLoop:
148153
for {
149154
// check if client is allowed to run
@@ -170,7 +175,7 @@ MainLoop:
170175
_, err = dataStore.DeleteJob(job.ID.Hex())
171176
worker.ProcessJob(dataStore, client, job, resumeChan)
172177
if err != nil {
173-
_ = glg.Failf("couldn't delete job, program has to pause to prevent endless loop")
178+
_ = glg.Failf("couldn't delete job, program has to pause to prevent it from retaking the job")
174179
state.Paused = true
175180
}
176181
}
@@ -197,7 +202,7 @@ MainLoop:
197202
}
198203

199204
// refresh client after sleeping time to ensure settings are updated properly
200-
client, err := dataStore.GetClientForMachine()
205+
client, err = dataStore.GetClientForMachine()
201206
if err != nil {
202207
_ = glg.Warnf("could not refresh client %s, using cached data", client.Name)
203208
}

0 commit comments

Comments
 (0)