fix image.Service termination in case Submit was never called

This commit is contained in:
Dmitry Verkhoturov
2020-04-12 03:34:13 -05:00
committed by Umputun
parent 97d7467033
commit 449e375cbb
2 changed files with 26 additions and 20 deletions
+14 -12
View File
@@ -480,18 +480,6 @@ func (a *serverApp) run(ctx context.Context) error {
<-ctx.Done()
log.Print("[INFO] shutdown initiated")
a.restSrv.Shutdown()
if a.devAuth != nil {
a.devAuth.Shutdown()
}
if e := a.dataService.Close(); e != nil {
log.Printf("[WARN] failed to close data store, %s", e)
}
if e := a.avatarStore.Close(); e != nil {
log.Printf("[WARN] failed to close avatar store, %s", e)
}
a.notifyService.Close()
a.imageService.Close()
log.Print("[INFO] shutdown completed")
}()
a.activateBackup(ctx) // runs in goroutine for each site
@@ -502,6 +490,20 @@ func (a *serverApp) run(ctx context.Context) error {
go a.imageService.Cleanup(ctx) // pictures cleanup for staging images
a.restSrv.Run(a.Port)
// shutdown procedures after HTTP server is stopped
if a.devAuth != nil {
a.devAuth.Shutdown()
}
if e := a.dataService.Close(); e != nil {
log.Printf("[WARN] failed to close data store, %s", e)
}
if e := a.avatarStore.Close(); e != nil {
log.Printf("[WARN] failed to close avatar store, %s", e)
}
a.notifyService.Close()
a.imageService.Close()
close(a.terminated)
return nil
}