New (shutdown/graceful.go)

AegisVision-Computer-Vision-System · pkg/platform/shutdown/graceful.go · go · Apache-2.0
infra, tag:knn-classified

A generic shutdown runner that registers closers and runs them on SIGINT/SIGTERM, waiting up to a grace period.

// Source: https://github.com/hoangsonww/AegisVision-Computer-Vision-System | License: Apache-2.0 | Copyright You must retain, in the Source form of any Derivative Works
// Provided via justclaw.it.com; keep this notice with the code.
// Package shutdown coordinates graceful termination across a service.
//
// On SIGINT/SIGTERM the runner stops accepting new work, waits for in-flight
// work to finish (up to GracePeriod), and calls every registered Closer in
// LIFO order. This matches the Kubernetes preStop + terminationGracePeriod
// contract: SIGTERM arrives, we flip readiness to red, drain, then exit.
package shutdown

import (
	"context"
	"errors"
	"log/slog"
	"os"
	"os/signal"
	"sync"
	"syscall"
	"time"
)

// Closer is anything that needs to release resources at shutdown — an HTTP
//

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key