feat: cache: fatal() helper to gracefully terminate the runner

in case of an error that is not recoverable (e.g. failing to open the
bolthold database), the cache can call fatal() to log the error and
send a TERM signal that will gracefully shutdown the daemon.
This commit is contained in:
Earl Warren 2025-09-04 16:55:26 +02:00
parent 98552f9b99
commit 36ca627f2e
No known key found for this signature in database
GPG key ID: 0579CB2928A78A00
2 changed files with 51 additions and 0 deletions

View file

@ -13,6 +13,7 @@ import (
"strconv"
"strings"
"sync/atomic"
"syscall"
"time"
"github.com/julienschmidt/httprouter"
@ -27,6 +28,13 @@ const (
urlBase = "/_apis/artifactcache"
)
var fatal = func(logger logrus.FieldLogger, err error) {
logger.Errorf("unrecoverable error in the cache: %v", err)
if err := syscall.Kill(syscall.Getpid(), syscall.SIGTERM); err != nil {
logger.Errorf("unrecoverable error in the cache: failed to send the TERM signal to shutdown the daemon %v", err)
}
}
type Handler interface {
ExternalURL() string
Close() error