feat(storage): add native PostgreSQL runtime and verified offline application import
Build and publish container images / images (push) Failing after 12m29s
Build and publish container images / images (push) Failing after 12m29s
This commit is contained in:
1 parent
96065d1e89
commit
0ba1dcfef0
243 files changed
+21441
-3090
No files matched your search
@@ -0,0 +1,57 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Close waits for the scheduler loop, maintenance and all running handlers
|
||||
// before releasing database worker ownership. Deadline expiry leaves ownership
|
||||
// held until the in-flight work actually exits; callers must not close the DB.
|
||||
func (s *Server) Close(ctx context.Context) error {
|
||||
s.closeOnce.Do(func() {
|
||||
s.backgroundCancel()
|
||||
go func() {
|
||||
_ = s.eventRunner().Stop(context.Background())
|
||||
s.backgroundWG.Wait()
|
||||
if s.workerRelease != nil {
|
||||
s.closeErr = s.workerRelease()
|
||||
}
|
||||
close(s.closeDone)
|
||||
}()
|
||||
})
|
||||
select {
|
||||
case <-s.closeDone:
|
||||
return s.closeErr
|
||||
case <-ctx.Done():
|
||||
return ctx.Err()
|
||||
}
|
||||
}
|
||||
|
||||
// RunContext drains HTTP before releasing worker ownership. If a request or
|
||||
// worker cannot stop in time, return an error without pretending it has exited.
|
||||
func (s *Server) RunContext(ctx context.Context, addr string) error {
|
||||
server := &http.Server{Addr: addr, Handler: s.handler(), ReadHeaderTimeout: 10 * time.Second}
|
||||
done := make(chan error, 1)
|
||||
go func() { done <- server.ListenAndServe() }()
|
||||
var serveErr error
|
||||
select {
|
||||
case serveErr = <-done:
|
||||
case <-ctx.Done():
|
||||
shutdown, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||
serveErr = server.Shutdown(shutdown)
|
||||
cancel()
|
||||
if serveErr != nil {
|
||||
_ = server.Close()
|
||||
}
|
||||
}
|
||||
closeCtx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||
defer cancel()
|
||||
closeErr := s.Close(closeCtx)
|
||||
if errors.Is(serveErr, http.ErrServerClosed) {
|
||||
serveErr = nil
|
||||
}
|
||||
return errors.Join(serveErr, closeErr)
|
||||
}
|
||||
Reference in new issue
Block a user