make it easy to turn the db on and off
This commit is contained in:
parent
c7643fb5da
commit
c088a65041
1 changed files with 27 additions and 14 deletions
|
@ -7,10 +7,11 @@ import (
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/lbryio/reflector.go/reflector"
|
||||||
|
|
||||||
"github.com/lbryio/reflector.go/db"
|
"github.com/lbryio/reflector.go/db"
|
||||||
"github.com/lbryio/reflector.go/meta"
|
"github.com/lbryio/reflector.go/meta"
|
||||||
"github.com/lbryio/reflector.go/peer"
|
"github.com/lbryio/reflector.go/peer"
|
||||||
"github.com/lbryio/reflector.go/reflector"
|
|
||||||
"github.com/lbryio/reflector.go/store"
|
"github.com/lbryio/reflector.go/store"
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
@ -35,9 +36,18 @@ func reflectorCmd(cmd *cobra.Command, args []string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
s3 := store.NewS3BlobStore(globalConfig.AwsID, globalConfig.AwsSecret, globalConfig.BucketRegion, globalConfig.BucketName)
|
s3 := store.NewS3BlobStore(globalConfig.AwsID, globalConfig.AwsSecret, globalConfig.BucketRegion, globalConfig.BucketName)
|
||||||
combo := store.NewDBBackedS3Store(s3, db)
|
|
||||||
|
|
||||||
reflectorServer := reflector.NewServer(combo)
|
// flip this flag to false when doing db maintenance. uploads will not work (as reflector server wont be running)
|
||||||
|
// but downloads will still work straight from s3
|
||||||
|
useDB := true
|
||||||
|
|
||||||
|
var reflectorServer *reflector.Server
|
||||||
|
var blobStore store.BlobStore = s3
|
||||||
|
|
||||||
|
if useDB {
|
||||||
|
blobStore = store.NewDBBackedS3Store(s3, db)
|
||||||
|
|
||||||
|
reflectorServer = reflector.NewServer(blobStore)
|
||||||
reflectorServer.Timeout = 3 * time.Minute
|
reflectorServer.Timeout = 3 * time.Minute
|
||||||
if globalConfig.SlackHookURL != "" {
|
if globalConfig.SlackHookURL != "" {
|
||||||
reflectorServer.StatLogger = log.StandardLogger()
|
reflectorServer.StatLogger = log.StandardLogger()
|
||||||
|
@ -49,8 +59,9 @@ func reflectorCmd(cmd *cobra.Command, args []string) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
peerServer := peer.NewServer(combo)
|
peerServer := peer.NewServer(blobStore)
|
||||||
if globalConfig.SlackHookURL != "" {
|
if globalConfig.SlackHookURL != "" {
|
||||||
peerServer.StatLogger = log.StandardLogger()
|
peerServer.StatLogger = log.StandardLogger()
|
||||||
peerServer.StatReportFrequency = 1 * time.Hour
|
peerServer.StatReportFrequency = 1 * time.Hour
|
||||||
|
@ -64,5 +75,7 @@ func reflectorCmd(cmd *cobra.Command, args []string) {
|
||||||
signal.Notify(interruptChan, os.Interrupt, syscall.SIGTERM)
|
signal.Notify(interruptChan, os.Interrupt, syscall.SIGTERM)
|
||||||
<-interruptChan
|
<-interruptChan
|
||||||
peerServer.Shutdown()
|
peerServer.Shutdown()
|
||||||
|
if reflectorServer != nil {
|
||||||
reflectorServer.Shutdown()
|
reflectorServer.Shutdown()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue