Commit c6bbdeb8 authored by Tomasz Maczukin's avatar Tomasz Maczukin

Allow cache commands to get timeout value from command line

parent 38ca607b
......@@ -18,8 +18,9 @@ import (
type CacheArchiverCommand struct {
fileArchiver
retryHelper
File string `long:"file" description:"The path to file"`
URL string `long:"url" description:"Download artifacts instead of uploading them"`
File string `long:"file" description:"The path to file"`
URL string `long:"url" description:"URL of remote cache resource"`
Timeout int `long:"timeout" description:"Overall timeout for cache uploading request (in minutes)"`
}
func (c *CacheArchiverCommand) upload() (bool, error) {
......@@ -44,7 +45,7 @@ func (c *CacheArchiverCommand) upload() (bool, error) {
req.Header.Set("Last-Modified", fi.ModTime().Format(http.TimeFormat))
req.ContentLength = fi.Size()
client := NewCacheClient()
client := NewCacheClient(c.Timeout)
resp, err := client.Do(req)
if err != nil {
return true, err
......
......@@ -4,14 +4,20 @@ import (
"net"
"net/http"
"time"
"gitlab.com/gitlab-org/gitlab-ci-multi-runner/common"
)
type CacheClient struct {
http.Client
}
func (c *CacheClient) prepareClient() {
c.Timeout = 3 * time.Minute
func (c *CacheClient) prepareClient(timeout int) {
if timeout > 0 {
c.Timeout = time.Duration(timeout) * time.Minute
} else {
c.Timeout = common.DefaultCacheRequestTimeout
}
}
func (c *CacheClient) prepareTransport() {
......@@ -28,9 +34,9 @@ func (c *CacheClient) prepareTransport() {
}
}
func NewCacheClient() *CacheClient {
func NewCacheClient(timeout int) *CacheClient {
client := &CacheClient{}
client.prepareClient()
client.prepareClient(timeout)
client.prepareTransport()
return client
......
......@@ -20,8 +20,9 @@ import (
type CacheExtractorCommand struct {
retryHelper
File string `long:"file" description:"The file containing your cache artifacts"`
URL string `long:"url" description:"Download artifacts instead of uploading them"`
File string `long:"file" description:"The file containing your cache artifacts"`
URL string `long:"url" description:"URL of remote cache resource"`
Timeout int `long:"timeout" description:"Overall timeout for cache downloading request (in minutes)"`
}
func (c *CacheExtractorCommand) download() (bool, error) {
......@@ -34,7 +35,7 @@ func (c *CacheExtractorCommand) download() (bool, error) {
defer file.Close()
defer os.Remove(file.Name())
client := NewCacheClient()
client := NewCacheClient(c.Timeout)
resp, err := client.Get(c.URL)
if err != nil {
return true, err
......
......@@ -23,5 +23,6 @@ const KubernetesPollInterval = 3
const KubernetesPollTimeout = 180
const AfterScriptTimeout = 5 * time.Minute
const DefaultMetricsServerPort = 9252
const DefaultCacheRequestTimeout = 10 * time.Minute
var PreparationRetryInterval = 3 * time.Second
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment