mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-04-19 19:28:22 +00:00
Make HTTP server wait for tasks before shutdown
This commit is contained in:
@@ -65,6 +65,7 @@ func aptlyAPIServe(cmd *commander.Command, args []string) error {
|
||||
signal.Notify(sigchan, syscall.SIGINT, syscall.SIGTERM)
|
||||
go (func() {
|
||||
if _, ok := <-sigchan; ok {
|
||||
context.TaskList().Wait()
|
||||
server.Shutdown(stdcontext.Background())
|
||||
}
|
||||
})()
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
"runtime/pprof"
|
||||
"strings"
|
||||
"sync"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/aptly-dev/aptly/aptly"
|
||||
@@ -359,10 +360,7 @@ func (context *AptlyContext) ReOpenDatabase() error {
|
||||
|
||||
// NewCollectionFactory builds factory producing all kinds of collections
|
||||
func (context *AptlyContext) NewCollectionFactory() *deb.CollectionFactory {
|
||||
context.Lock()
|
||||
defer context.Unlock()
|
||||
|
||||
db, err := context._database()
|
||||
db, err := context.Database()
|
||||
if err != nil {
|
||||
Fatal(err)
|
||||
}
|
||||
@@ -560,7 +558,7 @@ func (context *AptlyContext) GoContextHandleSignals() {
|
||||
|
||||
// Catch ^C
|
||||
sigch := make(chan os.Signal, 1)
|
||||
signal.Notify(sigch, os.Interrupt)
|
||||
signal.Notify(sigch, syscall.SIGINT, syscall.SIGTERM)
|
||||
|
||||
var cancel gocontext.CancelFunc
|
||||
|
||||
|
||||
@@ -133,6 +133,8 @@ func retryableError(err error) bool {
|
||||
}
|
||||
|
||||
switch err {
|
||||
case context.Canceled:
|
||||
return false
|
||||
case io.EOF:
|
||||
return true
|
||||
case io.ErrUnexpectedEOF:
|
||||
|
||||
Reference in New Issue
Block a user