1
0
Fork 0
mirror of https://github.com/postmannen/ctrl.git synced 2024-12-14 12:37:31 +00:00

moved the error kernel out into it's own type

This commit is contained in:
postmannen 2021-02-05 13:56:42 +01:00
parent 8db29c7e2f
commit f4d7f40c86
3 changed files with 52 additions and 7 deletions

View file

@ -82,4 +82,4 @@ and for a shell command of type command to a host named "ship2"
- Check that there is a node for the specific message new incomming message, and the supervisor should create the process with the wanted subject on both the publishing and the receiving node. If there is no such node an error should be generated and processed by the error-kernel.
- Since a process will be locked while waiting to send the error on the errorCh maybe it makes sense to have a channel inside the processes error handling with a select so we can send back to the process if it should continue or not based not based on how severe the error where. This should be right after sending the error sending in the process.
- Since a process will be locked while waiting to send the error on the errorCh maybe it makes sense to have a channel inside the processes error handling with a select so we can send back to the process if it should continue or not based not based on how severe the error where. This should be right after sending the error sending in the process.

28
erroringbuffer.go Normal file
View file

@ -0,0 +1,28 @@
package steward
// // ringBuffer holds the data of the buffer,
// type ringBuffer struct {
// data []string
// }
//
// // newringBuffer is a push/pop storage for values.
// func newringBuffer() *ringBuffer {
// return &ringBuffer{}
// }
//
// // push will add another item to the end of the buffer with a normal append
// func (s *ringBuffer) push(d string) {
// s.data = append(s.data, d)
// }
//
// // pop will remove and return the first element of the buffer
// func (s *ringBuffer) pop() string {
// if len(s.data) == 0 {
// return ""
// }
//
// v := s.data[0]
// s.data = append(s.data[0:0], s.data[1:]...)
//
// return v
// }

View file

@ -63,6 +63,8 @@ type server struct {
// errorCh is used to report errors from a process
// NB: Implementing this as an int to report for testing
errorCh chan string
// errorKernel
errorKernel *errorKernel
}
// newServer will prepare and return a server type
@ -80,14 +82,16 @@ func NewServer(brokerAddress string, nodeName string) (*server, error) {
errorCh: make(chan string, 10),
}
// Start the error kernel that will do all the error handling
// not done within a process.
s.errorKernel = newErrorKernel()
s.errorKernel.startErrorKernel(s.errorCh)
return s, nil
}
func (s *server) PublisherStart() {
// Start the error handler
s.startErrorKernel()
// Start the checking the input file for new messages from operator.
go getMessagesFromFile("./", "inmsg.txt", s.newMessagesCh)
@ -113,6 +117,19 @@ func (s *server) PublisherStart() {
}
// errorKernel is the structure that will hold all the error
// handling values and logic.
type errorKernel struct {
// ringBuffer *ringBuffer
}
// newErrorKernel will initialize and return a new error kernel
func newErrorKernel() *errorKernel {
return &errorKernel{
// ringBuffer: newringBuffer(),
}
}
// startErrorKernel will start the error kernel and check if there
// have been reveived any errors from any of the processes, and
// handle them appropriately.
@ -122,14 +139,14 @@ func (s *server) PublisherStart() {
// process if it should continue or not based not based on how severe
// the error where. This should be right after sending the error
// sending in the process.
func (s *server) startErrorKernel() {
func (e *errorKernel) startErrorKernel(errorCh chan string) {
// TODO: For now it will just print the error messages to the
// console.
go func() {
for {
e := <-s.errorCh
log.Printf("*** ERROR_KERNEL: %#v, type=%T\n", e, e)
er := <-errorCh
log.Printf("*** ERROR_KERNEL: %#v, type=%T\n", er, er)
}
}()
}