mirror of
https://github.com/tuna/tunasync.git
synced 2025-04-20 20:22:46 +00:00
add a timeout field to providers
This commit is contained in:
parent
e8c7ff3d7f
commit
e47ba2097e
@ -16,6 +16,7 @@ type baseProvider struct {
|
|||||||
name string
|
name string
|
||||||
interval time.Duration
|
interval time.Duration
|
||||||
retry int
|
retry int
|
||||||
|
timeout time.Duration
|
||||||
isMaster bool
|
isMaster bool
|
||||||
|
|
||||||
cmd *cmdJob
|
cmd *cmdJob
|
||||||
@ -56,6 +57,10 @@ func (p *baseProvider) Retry() int {
|
|||||||
return p.retry
|
return p.retry
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *baseProvider) Timeout() time.Duration {
|
||||||
|
return p.timeout
|
||||||
|
}
|
||||||
|
|
||||||
func (p *baseProvider) IsMaster() bool {
|
func (p *baseProvider) IsMaster() bool {
|
||||||
return p.isMaster
|
return p.isMaster
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@ type cmdConfig struct {
|
|||||||
workingDir, logDir, logFile string
|
workingDir, logDir, logFile string
|
||||||
interval time.Duration
|
interval time.Duration
|
||||||
retry int
|
retry int
|
||||||
|
timeout time.Duration
|
||||||
env map[string]string
|
env map[string]string
|
||||||
failOnMatch string
|
failOnMatch string
|
||||||
sizePattern string
|
sizePattern string
|
||||||
@ -41,6 +42,7 @@ func newCmdProvider(c cmdConfig) (*cmdProvider, error) {
|
|||||||
ctx: NewContext(),
|
ctx: NewContext(),
|
||||||
interval: c.interval,
|
interval: c.interval,
|
||||||
retry: c.retry,
|
retry: c.retry,
|
||||||
|
timeout: c.timeout,
|
||||||
},
|
},
|
||||||
cmdConfig: c,
|
cmdConfig: c,
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
. "github.com/smartystreets/goconvey/convey"
|
. "github.com/smartystreets/goconvey/convey"
|
||||||
)
|
)
|
||||||
@ -140,7 +141,6 @@ use_ipv6 = true
|
|||||||
So(m.Name, ShouldEqual, "debian")
|
So(m.Name, ShouldEqual, "debian")
|
||||||
So(m.MirrorDir, ShouldEqual, "")
|
So(m.MirrorDir, ShouldEqual, "")
|
||||||
So(m.Provider, ShouldEqual, provTwoStageRsync)
|
So(m.Provider, ShouldEqual, provTwoStageRsync)
|
||||||
So(m.Timeout, ShouldEqual, 86400)
|
|
||||||
|
|
||||||
m = cfg.Mirrors[2]
|
m = cfg.Mirrors[2]
|
||||||
So(m.Name, ShouldEqual, "fedora")
|
So(m.Name, ShouldEqual, "fedora")
|
||||||
@ -321,6 +321,7 @@ log_dir = "/var/log/tunasync/{{.Name}}"
|
|||||||
mirror_dir = "/data/mirrors"
|
mirror_dir = "/data/mirrors"
|
||||||
concurrent = 10
|
concurrent = 10
|
||||||
interval = 240
|
interval = 240
|
||||||
|
timeout = 86400
|
||||||
retry = 3
|
retry = 3
|
||||||
|
|
||||||
[manager]
|
[manager]
|
||||||
@ -393,5 +394,6 @@ use_ipv6 = true
|
|||||||
rp, ok := p.(*rsyncProvider)
|
rp, ok := p.(*rsyncProvider)
|
||||||
So(ok, ShouldBeTrue)
|
So(ok, ShouldBeTrue)
|
||||||
So(rp.WorkingDir(), ShouldEqual, "/data/mirrors/debian-cd")
|
So(rp.WorkingDir(), ShouldEqual, "/data/mirrors/debian-cd")
|
||||||
|
So(p.Timeout(), ShouldEqual, 86400*time.Second)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -46,6 +46,7 @@ type mirrorProvider interface {
|
|||||||
|
|
||||||
Interval() time.Duration
|
Interval() time.Duration
|
||||||
Retry() int
|
Retry() int
|
||||||
|
Timeout() time.Duration
|
||||||
|
|
||||||
WorkingDir() string
|
WorkingDir() string
|
||||||
LogDir() string
|
LogDir() string
|
||||||
@ -91,6 +92,9 @@ func newMirrorProvider(mirror mirrorConfig, cfg *Config) mirrorProvider {
|
|||||||
if mirror.Retry == 0 {
|
if mirror.Retry == 0 {
|
||||||
mirror.Retry = cfg.Global.Retry
|
mirror.Retry = cfg.Global.Retry
|
||||||
}
|
}
|
||||||
|
if mirror.Timeout == 0 {
|
||||||
|
mirror.Timeout = cfg.Global.Timeout
|
||||||
|
}
|
||||||
logDir = formatLogDir(logDir, mirror)
|
logDir = formatLogDir(logDir, mirror)
|
||||||
|
|
||||||
// IsMaster
|
// IsMaster
|
||||||
@ -118,6 +122,7 @@ func newMirrorProvider(mirror mirrorConfig, cfg *Config) mirrorProvider {
|
|||||||
logFile: filepath.Join(logDir, "latest.log"),
|
logFile: filepath.Join(logDir, "latest.log"),
|
||||||
interval: time.Duration(mirror.Interval) * time.Minute,
|
interval: time.Duration(mirror.Interval) * time.Minute,
|
||||||
retry: mirror.Retry,
|
retry: mirror.Retry,
|
||||||
|
timeout: time.Duration(mirror.Timeout) * time.Second,
|
||||||
env: mirror.Env,
|
env: mirror.Env,
|
||||||
}
|
}
|
||||||
p, err := newCmdProvider(pc)
|
p, err := newCmdProvider(pc)
|
||||||
@ -144,6 +149,7 @@ func newMirrorProvider(mirror mirrorConfig, cfg *Config) mirrorProvider {
|
|||||||
useIPv4: mirror.UseIPv4,
|
useIPv4: mirror.UseIPv4,
|
||||||
interval: time.Duration(mirror.Interval) * time.Minute,
|
interval: time.Duration(mirror.Interval) * time.Minute,
|
||||||
retry: mirror.Retry,
|
retry: mirror.Retry,
|
||||||
|
timeout: time.Duration(mirror.Timeout) * time.Second,
|
||||||
}
|
}
|
||||||
p, err := newRsyncProvider(rc)
|
p, err := newRsyncProvider(rc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -168,6 +174,7 @@ func newMirrorProvider(mirror mirrorConfig, cfg *Config) mirrorProvider {
|
|||||||
useIPv6: mirror.UseIPv6,
|
useIPv6: mirror.UseIPv6,
|
||||||
interval: time.Duration(mirror.Interval) * time.Minute,
|
interval: time.Duration(mirror.Interval) * time.Minute,
|
||||||
retry: mirror.Retry,
|
retry: mirror.Retry,
|
||||||
|
timeout: time.Duration(mirror.Timeout) * time.Second,
|
||||||
}
|
}
|
||||||
p, err := newTwoStageRsyncProvider(rc)
|
p, err := newTwoStageRsyncProvider(rc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -28,6 +28,7 @@ func TestRsyncProvider(t *testing.T) {
|
|||||||
logDir: tmpDir,
|
logDir: tmpDir,
|
||||||
logFile: tmpFile,
|
logFile: tmpFile,
|
||||||
useIPv6: true,
|
useIPv6: true,
|
||||||
|
timeout: 100 * time.Second,
|
||||||
interval: 600 * time.Second,
|
interval: 600 * time.Second,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,6 +41,7 @@ func TestRsyncProvider(t *testing.T) {
|
|||||||
So(provider.LogDir(), ShouldEqual, c.logDir)
|
So(provider.LogDir(), ShouldEqual, c.logDir)
|
||||||
So(provider.LogFile(), ShouldEqual, c.logFile)
|
So(provider.LogFile(), ShouldEqual, c.logFile)
|
||||||
So(provider.Interval(), ShouldEqual, c.interval)
|
So(provider.Interval(), ShouldEqual, c.interval)
|
||||||
|
So(provider.Timeout(), ShouldEqual, c.timeout)
|
||||||
|
|
||||||
Convey("When entering a context (auto exit)", func() {
|
Convey("When entering a context (auto exit)", func() {
|
||||||
func() {
|
func() {
|
||||||
|
@ -19,6 +19,7 @@ type rsyncConfig struct {
|
|||||||
useIPv6, useIPv4 bool
|
useIPv6, useIPv4 bool
|
||||||
interval time.Duration
|
interval time.Duration
|
||||||
retry int
|
retry int
|
||||||
|
timeout time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
// An RsyncProvider provides the implementation to rsync-based syncing jobs
|
// An RsyncProvider provides the implementation to rsync-based syncing jobs
|
||||||
@ -43,6 +44,7 @@ func newRsyncProvider(c rsyncConfig) (*rsyncProvider, error) {
|
|||||||
ctx: NewContext(),
|
ctx: NewContext(),
|
||||||
interval: c.interval,
|
interval: c.interval,
|
||||||
retry: c.retry,
|
retry: c.retry,
|
||||||
|
timeout: c.timeout,
|
||||||
},
|
},
|
||||||
rsyncConfig: c,
|
rsyncConfig: c,
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@ type twoStageRsyncConfig struct {
|
|||||||
useIPv6 bool
|
useIPv6 bool
|
||||||
interval time.Duration
|
interval time.Duration
|
||||||
retry int
|
retry int
|
||||||
|
timeout time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
// An RsyncProvider provides the implementation to rsync-based syncing jobs
|
// An RsyncProvider provides the implementation to rsync-based syncing jobs
|
||||||
@ -54,6 +55,7 @@ func newTwoStageRsyncProvider(c twoStageRsyncConfig) (*twoStageRsyncProvider, er
|
|||||||
ctx: NewContext(),
|
ctx: NewContext(),
|
||||||
interval: c.interval,
|
interval: c.interval,
|
||||||
retry: c.retry,
|
retry: c.retry,
|
||||||
|
timeout: c.timeout,
|
||||||
},
|
},
|
||||||
twoStageRsyncConfig: c,
|
twoStageRsyncConfig: c,
|
||||||
stage1Options: []string{
|
stage1Options: []string{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user