mirror of
https://github.com/postmannen/ctrl.git
synced 2024-12-14 12:37:31 +00:00
restructured function logic for sending messages
This commit is contained in:
parent
7b230f1fc6
commit
130f9fc57e
1 changed files with 136 additions and 135 deletions
75
process.go
75
process.go
|
@ -589,20 +589,22 @@ func (p process) publishMessages(natsConn *nats.Conn) {
|
|||
// to jump back here to the beginning of the loop and continue
|
||||
// with the next message.
|
||||
for {
|
||||
var err error
|
||||
var m Message
|
||||
|
||||
// Wait and read the next message on the message channel, or
|
||||
// exit this function if Cancel are received via ctx.
|
||||
select {
|
||||
case m = <-p.subject.messageCh:
|
||||
case m := <-p.subject.messageCh:
|
||||
p.publishAMessage(m, zEnc, once, natsConn)
|
||||
case <-p.ctx.Done():
|
||||
er := fmt.Errorf("info: canceling publisher: %v", p.subject.name())
|
||||
//sendErrorLogMessage(p.toRingbufferCh, Node(p.node), er)
|
||||
log.Printf("%v\n", er)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (p process) publishAMessage(m Message, zEnc *zstd.Encoder, once sync.Once, natsConn *nats.Conn) {
|
||||
// Create the initial header, and set values below depending on the
|
||||
// various configuration options chosen.
|
||||
natsMsgHeader := nats.Header{}
|
||||
|
@ -619,7 +621,7 @@ func (p process) publishMessages(natsConn *nats.Conn) {
|
|||
if err != nil {
|
||||
er := fmt.Errorf("error: messageDeliverNats: cbor encode message failed: %v", err)
|
||||
p.processes.errorKernel.errSend(p, m, er)
|
||||
continue
|
||||
return
|
||||
}
|
||||
|
||||
natsMsgPayloadSerialized = b
|
||||
|
@ -628,11 +630,11 @@ func (p process) publishMessages(natsConn *nats.Conn) {
|
|||
default:
|
||||
var bufGob bytes.Buffer
|
||||
gobEnc := gob.NewEncoder(&bufGob)
|
||||
err = gobEnc.Encode(m)
|
||||
err := gobEnc.Encode(m)
|
||||
if err != nil {
|
||||
er := fmt.Errorf("error: messageDeliverNats: gob encode message failed: %v", err)
|
||||
p.processes.errorKernel.errSend(p, m, er)
|
||||
continue
|
||||
return
|
||||
}
|
||||
|
||||
natsMsgPayloadSerialized = bufGob.Bytes()
|
||||
|
@ -666,7 +668,7 @@ func (p process) publishMessages(natsConn *nats.Conn) {
|
|||
if err != nil {
|
||||
log.Printf("error: failed to write gzip: %v\n", err)
|
||||
gzipW.Close()
|
||||
continue
|
||||
return
|
||||
}
|
||||
gzipW.Close()
|
||||
|
||||
|
@ -677,7 +679,7 @@ func (p process) publishMessages(natsConn *nats.Conn) {
|
|||
|
||||
default: // no compression
|
||||
// Allways log the error to console.
|
||||
er := fmt.Errorf("error: compression type not defined: %v, setting default to zero compression", err)
|
||||
er := fmt.Errorf("error: compression type not defined, setting default to zero compression")
|
||||
log.Printf("%v\n", er)
|
||||
|
||||
// We only wan't to send the error message to errorCentral once.
|
||||
|
@ -705,34 +707,33 @@ func (p process) publishMessages(natsConn *nats.Conn) {
|
|||
p.processes.active.mu.Unlock()
|
||||
}
|
||||
|
||||
// Handle the error.
|
||||
// // Handle the error.
|
||||
// //
|
||||
// // NOTE: None of the processes above generate an error, so the the
|
||||
// // if clause will never be triggered. But keeping it here as an example
|
||||
// // for now for how to handle errors.
|
||||
// if err != nil {
|
||||
// // Create an error type which also creates a channel which the
|
||||
// // errorKernel will send back the action about what to do.
|
||||
// ep := errorEvent{
|
||||
// //errorType: logOnly,
|
||||
// process: p,
|
||||
// message: m,
|
||||
// errorActionCh: make(chan errorAction),
|
||||
// }
|
||||
// p.errorCh <- ep
|
||||
//
|
||||
// NOTE: None of the processes above generate an error, so the the
|
||||
// if clause will never be triggered. But keeping it here as an example
|
||||
// for now for how to handle errors.
|
||||
if err != nil {
|
||||
// Create an error type which also creates a channel which the
|
||||
// errorKernel will send back the action about what to do.
|
||||
ep := errorEvent{
|
||||
//errorType: logOnly,
|
||||
process: p,
|
||||
message: m,
|
||||
errorActionCh: make(chan errorAction),
|
||||
}
|
||||
p.errorCh <- ep
|
||||
|
||||
// Wait for the response action back from the error kernel, and
|
||||
// decide what to do. Should we continue, quit, or .... ?
|
||||
switch <-ep.errorActionCh {
|
||||
case errActionContinue:
|
||||
// Just log and continue
|
||||
log.Printf("The errAction was continue...so we're continuing\n")
|
||||
case errActionKill:
|
||||
log.Printf("The errAction was kill...so we're killing\n")
|
||||
// ....
|
||||
default:
|
||||
log.Printf("Info: publishMessages: The errAction was not defined, so we're doing nothing\n")
|
||||
}
|
||||
}
|
||||
}
|
||||
// // Wait for the response action back from the error kernel, and
|
||||
// // decide what to do. Should we continue, quit, or .... ?
|
||||
// switch <-ep.errorActionCh {
|
||||
// case errActionContinue:
|
||||
// // Just log and continue
|
||||
// log.Printf("The errAction was continue...so we're continuing\n")
|
||||
// case errActionKill:
|
||||
// log.Printf("The errAction was kill...so we're killing\n")
|
||||
// // ....
|
||||
// default:
|
||||
// log.Printf("Info: publishMessages: The errAction was not defined, so we're doing nothing\n")
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue