Add recheck and timeout parameters

This commit is contained in:
Richard Patel 2018-11-18 00:29:29 +01:00
parent 339175220d
commit 4464f34779
No known key found for this signature in database
GPG Key ID: C268B2BBDA2ABECB
4 changed files with 24 additions and 2 deletions

View File

@ -12,6 +12,8 @@ import (
var config struct { var config struct {
ServerUrl string ServerUrl string
Token string Token string
ServerTimeout time.Duration
Recheck time.Duration
ChunkSize uint ChunkSize uint
Retries int Retries int
Workers int Workers int
@ -26,6 +28,8 @@ var config struct {
const ( const (
ConfServerUrl = "server.url" ConfServerUrl = "server.url"
ConfToken = "server.token" ConfToken = "server.token"
ConfServerTimeout = "server.timeout"
ConfRecheck = "server.recheck"
ConfChunkSize = "server.upload_chunk" ConfChunkSize = "server.upload_chunk"
ConfTasks = "crawl.tasks" ConfTasks = "crawl.tasks"
ConfRetries = "crawl.retries" ConfRetries = "crawl.retries"
@ -46,6 +50,7 @@ func prepareConfig() {
viper.SetDefault(ConfAllocStats, 0) viper.SetDefault(ConfAllocStats, 0)
viper.SetDefault(ConfVerbose, false) viper.SetDefault(ConfVerbose, false)
viper.SetDefault(ConfPrintHTTP, false) viper.SetDefault(ConfPrintHTTP, false)
viper.SetDefault(ConfRecheck, 3 * time.Second)
viper.SetDefault(ConfChunkSize, "1 MB") viper.SetDefault(ConfChunkSize, "1 MB")
} }
@ -69,6 +74,10 @@ func readConfig() {
configMissing(ConfToken) configMissing(ConfToken)
} }
config.ServerTimeout = viper.GetDuration(ConfServerTimeout)
config.Recheck = viper.GetDuration(ConfRecheck)
config.ChunkSize = viper.GetSizeInBytes(ConfChunkSize) config.ChunkSize = viper.GetSizeInBytes(ConfChunkSize)
if config.ChunkSize < 100 { if config.ChunkSize < 100 {
configOOB(ConfChunkSize, config.ChunkSize) configOOB(ConfChunkSize, config.ChunkSize)

View File

@ -2,8 +2,19 @@
server: server:
# Connection URL # Connection URL
url: http://od-db.mine.terorie.com/api url: http://od-db.mine.terorie.com/api
# Server auth token # Server auth token
token: token:
# Request timeout
timeout: 60s
# Recheck interval
# The crawler periodically asks the server
# for new jobs. Sets the minimum wait time
# between /task/get requests to the server.
recheck: 1s
# Upload chunk size # Upload chunk size
# If the value is too high, the upload fails. # If the value is too high, the upload fails.
upload_chunk: 1 MB upload_chunk: 1 MB

View File

@ -59,7 +59,7 @@ func cmdBase(_ *cli.Context) error {
inRemotes := make(chan *OD) inRemotes := make(chan *OD)
go Schedule(forceCtx, inRemotes) go Schedule(forceCtx, inRemotes)
ticker := time.NewTicker(3 * time.Second) ticker := time.NewTicker(config.Recheck)
defer ticker.Stop() defer ticker.Stop()
for { for {
select { select {

View File

@ -17,7 +17,9 @@ const (
fileListChunkSize int64 = 5000000 // 5 mb fileListChunkSize int64 = 5000000 // 5 mb
) )
var serverClient = http.DefaultClient var serverClient = http.Client {
Timeout: config.ServerTimeout,
}
func FetchTask() (t *Task, err error) { func FetchTask() (t *Task, err error) {
res, err := serverClient.PostForm( res, err := serverClient.PostForm(