Add admin setting to change max concurrent workers

This commit is contained in:
viktorstrate
2020-09-21 21:32:30 +02:00
parent a4f53cbc35
commit 9c9807ecc9
14 changed files with 568 additions and 257 deletions

View File

@@ -62,3 +62,25 @@ func (r *mutationResolver) SetPeriodicScanInterval(ctx context.Context, interval
return dbInterval, nil
}
func (r *mutationResolver) SetScannerConcurrentWorkers(ctx context.Context, workers int) (int, error) {
if workers < 0 {
return 0, errors.New("concurrent workers must be positive")
}
_, err := r.Database.Exec("UPDATE site_info SET concurrent_workers = ?", workers)
if err != nil {
return 0, err
}
var dbWorkers int
row := r.Database.QueryRow("SELECT concurrent_workers FROM site_info")
if err = row.Scan(&dbWorkers); err != nil {
return 0, err
}
scanner.ChangeScannerConcurrentWorkers(dbWorkers)
return dbWorkers, nil
}