mirror of
https://github.com/terorie/od-database-crawler.git
synced 2025-04-19 10:26:43 +00:00
Add recheck and timeout parameters
This commit is contained in:
parent
339175220d
commit
4464f34779
@ -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)
|
||||||
|
11
config.yml
11
config.yml
@ -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
|
||||||
|
2
main.go
2
main.go
@ -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 {
|
||||||
|
@ -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(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user