pkg/stopper: init from utils.Stopper
This commit is contained in:
parent
3e4dc3834f
commit
00e4f70972
12
api/api.go
12
api/api.go
@ -1,4 +1,4 @@
|
||||
// Copyright 2015 clair authors
|
||||
// Copyright 2017 clair authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
@ -27,7 +27,7 @@ import (
|
||||
|
||||
"github.com/coreos/clair/api/context"
|
||||
"github.com/coreos/clair/config"
|
||||
"github.com/coreos/clair/utils"
|
||||
"github.com/coreos/clair/pkg/stopper"
|
||||
"github.com/coreos/pkg/capnslog"
|
||||
)
|
||||
|
||||
@ -35,7 +35,7 @@ const timeoutResponse = `{"Error":{"Message":"Clair failed to respond within the
|
||||
|
||||
var log = capnslog.NewPackageLogger("github.com/coreos/clair", "api")
|
||||
|
||||
func Run(config *config.APIConfig, ctx *context.RouteContext, st *utils.Stopper) {
|
||||
func Run(config *config.APIConfig, ctx *context.RouteContext, st *stopper.Stopper) {
|
||||
defer st.End()
|
||||
|
||||
// Do not run the API service if there is no config.
|
||||
@ -68,7 +68,7 @@ func Run(config *config.APIConfig, ctx *context.RouteContext, st *utils.Stopper)
|
||||
log.Info("main API stopped")
|
||||
}
|
||||
|
||||
func RunHealth(config *config.APIConfig, ctx *context.RouteContext, st *utils.Stopper) {
|
||||
func RunHealth(config *config.APIConfig, ctx *context.RouteContext, st *stopper.Stopper) {
|
||||
defer st.End()
|
||||
|
||||
// Do not run the API service if there is no config.
|
||||
@ -94,8 +94,8 @@ func RunHealth(config *config.APIConfig, ctx *context.RouteContext, st *utils.St
|
||||
|
||||
// listenAndServeWithStopper wraps graceful.Server's
|
||||
// ListenAndServe/ListenAndServeTLS and adds the ability to interrupt them with
|
||||
// the provided utils.Stopper
|
||||
func listenAndServeWithStopper(srv *graceful.Server, st *utils.Stopper, certFile, keyFile string) {
|
||||
// the provided stopper.Stopper.
|
||||
func listenAndServeWithStopper(srv *graceful.Server, st *stopper.Stopper, certFile, keyFile string) {
|
||||
go func() {
|
||||
<-st.Chan()
|
||||
srv.Stop(0)
|
||||
|
@ -32,8 +32,8 @@ import (
|
||||
"github.com/coreos/clair/config"
|
||||
"github.com/coreos/clair/database"
|
||||
"github.com/coreos/clair/notifier"
|
||||
"github.com/coreos/clair/pkg/stopper"
|
||||
"github.com/coreos/clair/updater"
|
||||
"github.com/coreos/clair/utils"
|
||||
|
||||
// Register database driver.
|
||||
_ "github.com/coreos/clair/database/pgsql"
|
||||
@ -91,7 +91,7 @@ func stopCPUProfiling(f *os.File) {
|
||||
// Boot starts Clair instance with the provided config.
|
||||
func Boot(config *config.Config) {
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
st := utils.NewStopper()
|
||||
st := stopper.NewStopper()
|
||||
|
||||
// Open database
|
||||
db, err := database.Open(config.Database)
|
||||
|
@ -29,7 +29,7 @@ import (
|
||||
"github.com/coreos/clair/database"
|
||||
"github.com/coreos/clair/ext/notification"
|
||||
"github.com/coreos/clair/pkg/commonerr"
|
||||
"github.com/coreos/clair/utils"
|
||||
"github.com/coreos/clair/pkg/stopper"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -59,7 +59,7 @@ func init() {
|
||||
}
|
||||
|
||||
// Run starts the Notifier service.
|
||||
func Run(config *config.NotifierConfig, datastore database.Datastore, stopper *utils.Stopper) {
|
||||
func Run(config *config.NotifierConfig, datastore database.Datastore, stopper *stopper.Stopper) {
|
||||
defer stopper.End()
|
||||
|
||||
// Configure registered notifiers.
|
||||
@ -122,7 +122,7 @@ func Run(config *config.NotifierConfig, datastore database.Datastore, stopper *u
|
||||
log.Info("notifier service stopped")
|
||||
}
|
||||
|
||||
func findTask(datastore database.Datastore, renotifyInterval time.Duration, whoAmI string, stopper *utils.Stopper) *database.VulnerabilityNotification {
|
||||
func findTask(datastore database.Datastore, renotifyInterval time.Duration, whoAmI string, stopper *stopper.Stopper) *database.VulnerabilityNotification {
|
||||
for {
|
||||
// Find a notification to send.
|
||||
notification, err := datastore.GetAvailableNotification(renotifyInterval)
|
||||
@ -148,7 +148,7 @@ func findTask(datastore database.Datastore, renotifyInterval time.Duration, whoA
|
||||
}
|
||||
}
|
||||
|
||||
func handleTask(n database.VulnerabilityNotification, st *utils.Stopper, maxAttempts int) (bool, bool) {
|
||||
func handleTask(n database.VulnerabilityNotification, st *stopper.Stopper, maxAttempts int) (bool, bool) {
|
||||
// Send notification.
|
||||
for senderName, sender := range notification.Senders() {
|
||||
var attempts int
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Copyright 2015 clair authors
|
||||
// Copyright 2017 clair authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
@ -12,7 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package utils
|
||||
package stopper
|
||||
|
||||
import (
|
||||
"sync"
|
@ -32,7 +32,7 @@ import (
|
||||
"github.com/coreos/clair/database"
|
||||
"github.com/coreos/clair/ext/vulnmdsrc"
|
||||
"github.com/coreos/clair/ext/vulnsrc"
|
||||
"github.com/coreos/clair/utils"
|
||||
"github.com/coreos/clair/pkg/stopper"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -70,7 +70,7 @@ func init() {
|
||||
}
|
||||
|
||||
// Run updates the vulnerability database at regular intervals.
|
||||
func Run(config *config.UpdaterConfig, datastore database.Datastore, st *utils.Stopper) {
|
||||
func Run(config *config.UpdaterConfig, datastore database.Datastore, st *stopper.Stopper) {
|
||||
defer st.End()
|
||||
|
||||
// Do not run the updater if there is no config or if the interval is 0.
|
||||
|
Loading…
Reference in New Issue
Block a user