Commit d45eeeb6 authored by Lukas Burgey's avatar Lukas Burgey
Browse files

Change the method order

parent 899c0c47
......@@ -132,40 +132,6 @@ func (c *config) fetchTasks() (err error) {
}
return
}
func (c *config) respondToTask(te taskExecution) (err error) {
responseBytes, err := json.Marshal(te)
if err != nil {
return
}
log.Printf("[Task] Sending ACK %v:\n%s", te.ID, responseBytes)
url := fmt.Sprintf("https://%s/backend/clientapi/response", c.Host)
req, err := http.NewRequest("POST", url, bytes.NewReader(responseBytes))
if err != nil {
// TODO retransmit ACK
return
}
req.SetBasicAuth(c.Username, c.Password)
req.Header.Set("Content-Type", "application/json")
// execute request
resp, err := http.DefaultClient.Do(req)
if err != nil {
return
}
defer resp.Body.Close()
if resp.StatusCode == 200 {
log.Printf("[Task] Backend received ACK %v", te.ID)
}
respBytes, err := ioutil.ReadAll(resp.Body)
if err != nil {
return
}
log.Printf("[Task] Backend response to ACK %v:\n%s", te.ID, respBytes)
return
}
func (c *config) handleTask(ti task) (err error) {
var output scripts.Output
......@@ -232,3 +198,37 @@ func (c *config) handleTask(ti task) (err error) {
c.DoneTasks <- taskExecution{ti.ID, output}
return
}
func (c *config) respondToTask(te taskExecution) (err error) {
responseBytes, err := json.Marshal(te)
if err != nil {
return
}
log.Printf("[Task] Sending ACK %v:\n%s", te.ID, responseBytes)
url := fmt.Sprintf("https://%s/backend/clientapi/response", c.Host)
req, err := http.NewRequest("POST", url, bytes.NewReader(responseBytes))
if err != nil {
// TODO retransmit ACK
return
}
req.SetBasicAuth(c.Username, c.Password)
req.Header.Set("Content-Type", "application/json")
// execute request
resp, err := http.DefaultClient.Do(req)
if err != nil {
return
}
defer resp.Body.Close()
if resp.StatusCode == 200 {
log.Printf("[Task] Backend received ACK %v", te.ID)
}
respBytes, err := ioutil.ReadAll(resp.Body)
if err != nil {
return
}
log.Printf("[Task] Backend response to ACK %v:\n%s", te.ID, respBytes)
return
}
Supports Markdown
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