Skip to content
Snippets Groups Projects
Commit 4bf18598 authored by Sybren A. Stüvel's avatar Sybren A. Stüvel
Browse files

Manager: use different HTTP headers to do conditional fetch of depsgraph

parent bc600269
No related branches found
No related tags found
No related merge requests found
......@@ -8,14 +8,12 @@ import (
"io/ioutil"
"net/http"
"net/url"
"time"
log "github.com/Sirupsen/logrus"
)
// For timestamp parsing
const IsoFormat = "2006-01-02T15:04:05-0700"
const LastModifiedHeaderFormat = time.RFC1123
/**
* Decodes JSON and writes a Bad Request status if it fails.
......
package flamenco
import (
"time"
"github.com/stretchr/testify/assert"
check "gopkg.in/check.v1"
)
type HttpTestSuite struct{}
var _ = check.Suite(&HttpTestSuite{})
func (s *HttpTestSuite) TestParseDates(c *check.C) {
parsed_iso, err1 := time.Parse(IsoFormat, "2017-01-23T13:04:05+0200")
parsed_http, err2 := time.Parse(LastModifiedHeaderFormat, "Mon, 23 Jan 2017 13:04:05 CEST")
assert.Nil(c, err1)
assert.Nil(c, err2)
assert.Equal(c, parsed_iso, parsed_http)
}
......@@ -159,7 +159,7 @@ func download_tasks_from_upstream(config *Conf, mongo_sess *mgo.Session) {
if settings.DepsgraphLastModified != nil {
log.Infof("Getting tasks from upstream Flamenco %s If-Modified-Since %s", get_url,
*settings.DepsgraphLastModified)
req.Header.Set("If-Modified-Since", *settings.DepsgraphLastModified)
req.Header.Set("X-Flamenco-If-Updated-Since", *settings.DepsgraphLastModified)
} else {
log.Infof("Getting tasks from upstream Flamenco %s", get_url)
}
......@@ -174,7 +174,7 @@ func download_tasks_from_upstream(config *Conf, mongo_sess *mgo.Session) {
log.Debug("Server-side depsgraph was not modified, nothing to do.")
return
}
if resp.StatusCode == 204 {
if resp.StatusCode == http.StatusNoContent {
log.Info("No tasks for us; sleeping.")
return
}
......@@ -223,7 +223,7 @@ func download_tasks_from_upstream(config *Conf, mongo_sess *mgo.Session) {
}
// Check if we had a Last-Modified header, since we need to remember that.
last_modified := resp.Header.Get("Last-Modified")
last_modified := resp.Header.Get("X-Flamenco-Last-Updated")
if last_modified != "" {
log.Info("Last modified task was at ", last_modified)
settings.DepsgraphLastModified = &last_modified
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment