1
0
Fork 0
mirror of https://github.com/postmannen/ctrl.git synced 2025-04-09 10:24:17 +00:00

Added logger for request method

This commit is contained in:
postmannen 2021-04-01 10:05:14 +02:00
parent 1b17f8e345
commit 62347e2943
4 changed files with 35 additions and 32 deletions

View file

@ -1,22 +0,0 @@
some message sent from a ship for testing
some message sent from a ship for testing
some message sent from a ship for testing
some message sent from a ship for testing
some message sent from a ship for testing
some message sent from a ship for testing
some message sent from a ship for testing
some message sent from a ship for testing
some message sent from a ship for testing
some message sent from a ship for testing
some message sent from a ship for testing
some message sent from a ship for testing
some message sent from a ship for testing
some message sent from a ship for testing
some message sent from a ship for testing
some message sent from a ship for testing
some message sent from a ship for testing
some message sent from a ship for testing
some message sent from a ship for testing
some message sent from a ship for testing
some message sent from a ship for testing
some message sent from a ship for testing

View file

@ -1,6 +0,0 @@
some message sent from a ship for testing
some message sent from a ship for testing
some message sent from a ship for testing
some message sent from a ship for testing
some message sent from a ship for testing
some message sent from a ship for testing

View file

@ -28,14 +28,19 @@ type Message struct {
RequestRetries int `json:"requestRetries" yaml:"requestRetries"`
// Timeout for long a process should be allowed to operate
MethodTimeout int `json:"methodTimeout" yaml:"methodTimeout"`
// msgOriginal are used for example if a reply message is
// generated and we also need a copy of thedetails of the
// the initial request message
MsgOrigSubject Subject
// done is used to signal when a message is fully processed.
// This is used when choosing when to move the message from
// the ringbuffer into the time series log.
done chan struct{}
}
// gobEncodePayload will encode the message structure along with its
// valued in gob binary format.
// gobEncodePayload will encode the message structure into gob
// binary format.
func gobEncodeMessage(m Message) ([]byte, error) {
var buf bytes.Buffer
gobEnc := gob.NewEncoder(&buf)

View file

@ -293,8 +293,12 @@ func newReplyMessage(proc process, message Message, method Method, outData []byt
Method: method,
Timeout: message.RequestTimeout,
Retries: message.RequestRetries,
MsgOrigSubject: Subject{
ToNode: string(message.ToNode),
Method: message.Method,
},
}
fmt.Printf("** %#v\n", newMsg)
fmt.Printf(" ** %#v\n", newMsg)
nSAM, err := newSAM(newMsg)
if err != nil {
@ -316,7 +320,29 @@ func (m methodOpCommandReply) getKind() CommandOrEvent {
}
func (m methodOpCommandReply) handler(proc process, message Message, node string) ([]byte, error) {
log.Printf("<--- OpCommand Reply received from: %v, containing: %v", message.FromNode, message.Data)
// Recreate the subject structure for the message, so we can use
// it in the naming of the files to create.
sub := Subject{
ToNode: string(message.MsgOrigSubject.ToNode),
CommandOrEvent: proc.subject.CommandOrEvent,
Method: message.MsgOrigSubject.Method,
}
logFile := filepath.Join(proc.configuration.SubscribersDataFolder, string(sub.name()))
f, err := os.OpenFile(logFile, os.O_APPEND|os.O_RDWR|os.O_CREATE, os.ModeAppend)
if err != nil {
log.Printf("error: methodEventTextLogging.handler: failed to open file: %v\n", err)
return nil, err
}
defer f.Close()
for _, d := range message.Data {
_, err := f.Write([]byte(d))
f.Sync()
if err != nil {
log.Printf("error: methodEventTextLogging.handler: failed to write to file: %v\n", err)
}
}
ackMsg := []byte("confirmed from: " + node + ": " + fmt.Sprint(message.ID))
return ackMsg, nil