Skip to content

Commit

Permalink
pkg/stopper: init from utils.Stopper
Browse files Browse the repository at this point in the history
  • Loading branch information
jzelinskie committed Jan 23, 2017
1 parent 3e4dc38 commit 00e4f70
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
12 changes: 6 additions & 6 deletions api/api.go
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -27,15 +27,15 @@ 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"
)

const timeoutResponse = `{"Error":{"Message":"Clair failed to respond within the configured timeout window.","Type":"Timeout"}}`

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.
Expand Down Expand Up @@ -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.
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions cmd/clair/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions notifier/notifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions utils/stopper.go → pkg/stopper/stopper.go
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package utils
package stopper

import (
"sync"
Expand Down
4 changes: 2 additions & 2 deletions updater/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 00e4f70

Please sign in to comment.