mirror of
https://github.com/postmannen/ctrl.git
synced 2024-12-14 12:37:31 +00:00
removed server from method type
This commit is contained in:
parent
ae0e080f80
commit
d6310492a3
2 changed files with 12 additions and 8 deletions
|
@ -50,6 +50,8 @@ type process struct {
|
||||||
// The channel to send a messages to the procFunc go routine.
|
// The channel to send a messages to the procFunc go routine.
|
||||||
// This is typically used within the methodHandler.
|
// This is typically used within the methodHandler.
|
||||||
procFuncCh chan Message
|
procFuncCh chan Message
|
||||||
|
// copy of the configuration from server
|
||||||
|
configuration *Configuration
|
||||||
}
|
}
|
||||||
|
|
||||||
// prepareNewProcess will set the the provided values and the default
|
// prepareNewProcess will set the the provided values and the default
|
||||||
|
@ -88,6 +90,8 @@ func newProcess(processes *processes, subject Subject, errCh chan errProcess, pr
|
||||||
// It will give the process the next available ID, and also add the
|
// It will give the process the next available ID, and also add the
|
||||||
// process to the processes map in the server structure.
|
// process to the processes map in the server structure.
|
||||||
func (p process) spawnWorker(s *server) {
|
func (p process) spawnWorker(s *server) {
|
||||||
|
// Copy the configuration from Server
|
||||||
|
p.configuration = s.configuration
|
||||||
// We use the full name of the subject to identify a unique
|
// We use the full name of the subject to identify a unique
|
||||||
// process. We can do that since a process can only handle
|
// process. We can do that since a process can only handle
|
||||||
// one message queue.
|
// one message queue.
|
||||||
|
@ -251,7 +255,7 @@ func (p process) subscriberHandler(natsConn *nats.Conn, thisNode string, msg *na
|
||||||
// The handler started here is what actually doing the action
|
// The handler started here is what actually doing the action
|
||||||
// that executed a CLI command, or writes to a log file on
|
// that executed a CLI command, or writes to a log file on
|
||||||
// the node who received the message.
|
// the node who received the message.
|
||||||
out, err = mf.handler(s, p, message, thisNode)
|
out, err = mf.handler(p, message, thisNode)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// TODO: Send to error kernel ?
|
// TODO: Send to error kernel ?
|
||||||
|
@ -286,7 +290,7 @@ func (p process) subscriberHandler(natsConn *nats.Conn, thisNode string, msg *na
|
||||||
// since we don't send a reply for a NACK message, we don't care about the
|
// since we don't send a reply for a NACK message, we don't care about the
|
||||||
// out return when calling mf.handler
|
// out return when calling mf.handler
|
||||||
//fmt.Printf("-- DEBUG 2.2.1: %#v\n\n", p.subject)
|
//fmt.Printf("-- DEBUG 2.2.1: %#v\n\n", p.subject)
|
||||||
_, err := mf.handler(s, p, message, thisNode)
|
_, err := mf.handler(p, message, thisNode)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// TODO: Send to error kernel ?
|
// TODO: Send to error kernel ?
|
||||||
|
|
|
@ -120,7 +120,7 @@ func (ma MethodsAvailable) CheckIfExists(m Method) (methodHandler, bool) {
|
||||||
// ------------------------------------------------------------
|
// ------------------------------------------------------------
|
||||||
|
|
||||||
type methodHandler interface {
|
type methodHandler interface {
|
||||||
handler(server *server, proc process, message Message, node string) ([]byte, error)
|
handler(proc process, message Message, node string) ([]byte, error)
|
||||||
getKind() CommandOrEvent
|
getKind() CommandOrEvent
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,7 +134,7 @@ func (m methodCommandCLICommand) getKind() CommandOrEvent {
|
||||||
return m.commandOrEvent
|
return m.commandOrEvent
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m methodCommandCLICommand) handler(s *server, proc process, message Message, node string) ([]byte, error) {
|
func (m methodCommandCLICommand) handler(proc process, message Message, node string) ([]byte, error) {
|
||||||
// Since the command to execute is at the first position in the
|
// Since the command to execute is at the first position in the
|
||||||
// slice we need to slice it out. The arguments are at the
|
// slice we need to slice it out. The arguments are at the
|
||||||
// remaining positions.
|
// remaining positions.
|
||||||
|
@ -161,14 +161,14 @@ func (m methodEventTextLogging) getKind() CommandOrEvent {
|
||||||
return m.commandOrEvent
|
return m.commandOrEvent
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m methodEventTextLogging) handler(s *server, proc process, message Message, node string) ([]byte, error) {
|
func (m methodEventTextLogging) handler(proc process, message Message, node string) ([]byte, error) {
|
||||||
sub := Subject{
|
sub := Subject{
|
||||||
ToNode: string(message.ToNode),
|
ToNode: string(message.ToNode),
|
||||||
CommandOrEvent: proc.subject.CommandOrEvent,
|
CommandOrEvent: proc.subject.CommandOrEvent,
|
||||||
Method: message.Method,
|
Method: message.Method,
|
||||||
}
|
}
|
||||||
|
|
||||||
logFile := filepath.Join(s.configuration.SubscribersDataFolder, string(sub.name())+"-"+string(message.FromNode))
|
logFile := filepath.Join(proc.configuration.SubscribersDataFolder, string(sub.name())+"-"+string(message.FromNode))
|
||||||
f, err := os.OpenFile(logFile, os.O_APPEND|os.O_RDWR|os.O_CREATE, os.ModeAppend)
|
f, err := os.OpenFile(logFile, os.O_APPEND|os.O_RDWR|os.O_CREATE, os.ModeAppend)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("error: methodEventTextLogging.handler: failed to open file: %v\n", err)
|
log.Printf("error: methodEventTextLogging.handler: failed to open file: %v\n", err)
|
||||||
|
@ -200,7 +200,7 @@ func (m methodEventSayHello) getKind() CommandOrEvent {
|
||||||
return m.commandOrEvent
|
return m.commandOrEvent
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m methodEventSayHello) handler(s *server, proc process, message Message, node string) ([]byte, error) {
|
func (m methodEventSayHello) handler(proc process, message Message, node string) ([]byte, error) {
|
||||||
//fmt.Printf("-- DEBUG 3.1: %#v, %#v, %#v\n\n", proc.subject.name(), proc.procFunc, proc.procFuncCh)
|
//fmt.Printf("-- DEBUG 3.1: %#v, %#v, %#v\n\n", proc.subject.name(), proc.procFunc, proc.procFuncCh)
|
||||||
//pn := processNameGet(proc.subject.name(), processKindSubscriber)
|
//pn := processNameGet(proc.subject.name(), processKindSubscriber)
|
||||||
//fmt.Printf("-- DEBUG 3.2: pn = %#v\n\n", pn)
|
//fmt.Printf("-- DEBUG 3.2: pn = %#v\n\n", pn)
|
||||||
|
@ -226,7 +226,7 @@ func (m methodEventErrorLog) getKind() CommandOrEvent {
|
||||||
return m.commandOrEvent
|
return m.commandOrEvent
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m methodEventErrorLog) handler(s *server, proc process, message Message, node string) ([]byte, error) {
|
func (m methodEventErrorLog) handler(proc process, message Message, node string) ([]byte, error) {
|
||||||
log.Printf("<--- Received error from: %v, containing: %v", message.FromNode, message.Data)
|
log.Printf("<--- Received error from: %v, containing: %v", message.FromNode, message.Data)
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue