2018-10-02 20:46:29 +01:00
|
|
|
// Copyright (C) 2018 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package checker
|
2018-10-03 19:35:56 +01:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2018-10-04 22:40:34 +01:00
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/zeebo/errs"
|
|
|
|
"go.uber.org/zap"
|
|
|
|
monkit "gopkg.in/spacemonkeygo/monkit.v2"
|
|
|
|
|
|
|
|
"storj.io/storj/pkg/provider"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
mon = monkit.Package()
|
|
|
|
// Error is a standard error class for this package.
|
|
|
|
Error = errs.Class("checker error")
|
2018-10-03 19:35:56 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// Config contains configurable values for checker
|
|
|
|
type Config struct {
|
2018-10-05 16:58:07 +01:00
|
|
|
// QueueAddress string `help:"data repair queue address" default:"redis://localhost:6379?db=5&password=123"`
|
2018-10-04 22:40:34 +01:00
|
|
|
Interval time.Duration `help:"how frequently checker should audit segments" default:"30s"`
|
2018-10-03 19:35:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Run runs the checker with configured values
|
2018-10-04 22:40:34 +01:00
|
|
|
func (c Config) Run(ctx context.Context, server *provider.Provider) (err error) {
|
|
|
|
defer mon.Task()(&ctx)(&err)
|
|
|
|
|
|
|
|
zap.S().Info("Checker is starting up")
|
|
|
|
|
|
|
|
ticker := time.NewTicker(c.Interval)
|
|
|
|
defer ticker.Stop()
|
|
|
|
|
|
|
|
ctx, cancel := context.WithCancel(ctx)
|
|
|
|
defer cancel()
|
2018-10-03 19:35:56 +01:00
|
|
|
|
2018-10-04 22:40:34 +01:00
|
|
|
go func() {
|
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case <-ticker.C:
|
|
|
|
zap.S().Info("Starting segment checker service")
|
|
|
|
case <-ctx.Done():
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
2018-10-03 19:35:56 +01:00
|
|
|
|
2018-10-04 22:40:34 +01:00
|
|
|
return server.Run(ctx)
|
2018-10-03 19:35:56 +01:00
|
|
|
}
|