Skip to content

Commit

Permalink
fix: Return proper values, when worker is in remote-content mode
Browse files Browse the repository at this point in the history
* When worker works in remote-content mode and address is set
  to some URL, then the Transmit function should return
  values according to result of HTTP request POST
  • Loading branch information
jirihnidek authored and subpop committed Jul 18, 2023
1 parent f29f6eb commit 0da66f8
Showing 1 changed file with 39 additions and 27 deletions.
66 changes: 39 additions & 27 deletions internal/work/dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,35 +274,47 @@ func (d *Dispatcher) Transmit(sender dbus.Sender, addr string, messageID string,
if err != nil {
return TransmitResponseErr, nil, nil, NewDBusError("Transmit", fmt.Sprintf("cannot read HTTP response body: %v", err))
}
resp.Body.Close()
}
}

ch := make(chan yggdrasil.Response)
d.Outbound <- struct {
Data yggdrasil.Data
Resp chan yggdrasil.Response
}{
Data: yggdrasil.Data{
Type: yggdrasil.MessageTypeData,
MessageID: messageID,
ResponseTo: responseTo,
Version: 1,
Sent: time.Now(),
Directive: addr,
Metadata: metadata,
Content: data,
},
Resp: ch,
}
err = resp.Body.Close()
if err != nil {
return TransmitResponseErr, nil, nil, NewDBusError("Transmit", fmt.Sprintf("cannot close HTTP response body: %v", err))
}
responseCode = resp.StatusCode
responseMetadata = make(map[string]string)
for header := range resp.Header {
responseMetadata[header] = resp.Header.Get(header)
}
responseData = data
} else {
return TransmitResponseErr, nil, nil, NewDBusError("Transmit", fmt.Sprintf("URL: '%v' has no scheme", addr))
}
} else {
ch := make(chan yggdrasil.Response)
d.Outbound <- struct {
Data yggdrasil.Data
Resp chan yggdrasil.Response
}{
Data: yggdrasil.Data{
Type: yggdrasil.MessageTypeData,
MessageID: messageID,
ResponseTo: responseTo,
Version: 1,
Sent: time.Now(),
Directive: addr,
Metadata: metadata,
Content: data,
},
Resp: ch,
}

select {
case resp := <-ch:
responseCode = resp.Code
responseMetadata = resp.Metadata
responseData = resp.Data
case <-time.After(1 * time.Second):
return TransmitResponseErr, nil, nil, NewDBusError("com.redhat.Yggdrasil1.Dispatcher1.Transmit", "timeout reached waiting for response")
select {
case resp := <-ch:
responseCode = resp.Code
responseMetadata = resp.Metadata
responseData = resp.Data
case <-time.After(1 * time.Second):
return TransmitResponseErr, nil, nil, NewDBusError("com.redhat.Yggdrasil1.Dispatcher1.Transmit", "timeout reached waiting for response")
}
}
return
}
Expand Down

0 comments on commit 0da66f8

Please sign in to comment.