storj/pkg/datarepair/repairer/config.go
Egon Elbre 2a8b681c4d
Run repairer and checker early (#565)
* Run repairers, checker, auditors first time they run to detect potential setup problems.
* Fix error handling in audit.Service
2018-11-01 16:03:45 +02:00

43 lines
1.2 KiB
Go

// Copyright (C) 2018 Storj Labs, Inc.
// See LICENSE for copying information.
package repairer
import (
"context"
"time"
"go.uber.org/zap"
"storj.io/storj/pkg/datarepair/queue"
"storj.io/storj/pkg/provider"
"storj.io/storj/storage/redis"
)
// Config contains configurable values for repairer
type Config struct {
QueueAddress string `help:"data repair queue address" default:"redis://127.0.0.1:6378?db=1&password=abc123"`
MaxRepair int `help:"maximum segments that can be repaired concurrently" default:"100"`
Interval time.Duration `help:"how frequently checker should audit segments" default:"3600s"`
}
// Run runs the repairer with configured values
func (c Config) Run(ctx context.Context, server *provider.Provider) (err error) {
client, err := redis.NewClientFrom(c.QueueAddress)
if err != nil {
return Error.Wrap(err)
}
queue := queue.NewQueue(client)
repairer := newRepairer(queue, c.Interval, c.MaxRepair)
// TODO(coyle): we need to figure out how to propagate the error up to cancel the service
go func() {
if err := repairer.Run(ctx); err != nil {
zap.L().Error("Error running repairer", zap.Error(err))
}
}()
return server.Run(ctx)
}