@ -3,7 +3,7 @@ package server
import (
"fmt"
"time"
"log"
_ "log"
"context"
"sync"
"FRMS/internal/pkg/logging"
@ -39,6 +39,7 @@ func NewReactorManager(c *Client,sys *SystemViewer,err chan error) GeneralManage
func ( r * ReactorManager ) Start ( cl * Client ) {
r . Manager . Start ( cl )
logging . Debug ( logging . DStart , "RMA %v starting" , r . Id )
go r . StatusMon . Start ( )
go r . DevsMon . Start ( )
go r . StatusMon . Send ( & DeviceInfo { Id : r . Id , Type : "Reactor" , Status : "[green]ONLINE[white]" } )
@ -51,6 +52,7 @@ func (r *ReactorManager) Start(cl *Client) {
func ( r * ReactorManager ) Exit ( ) {
r . Manager . Exit ( )
logging . Debug ( logging . DExit , "RMA %v exiting" , r . Id )
go r . StatusMon . Send ( & DeviceInfo { Id : r . Id , Type : "Reactor" , Status : "[red]OFFLINE[white]" , Data : fmt . Sprintf ( "Last Seen %v" , time . Now ( ) . Format ( "Mon at 03:04:05pm MST" ) ) } )
}
@ -66,7 +68,7 @@ func (r *ReactorManager) Connect() *grpc.ClientConn {
for {
if ! r . IsActive ( ) {
logging . Debug ( logging . DClient , " No longer active, aborting connection attempt\n ")
logging . Debug ( logging . DClient , " RMA %v No longer active, aborting connection attempt", r . Id )
return & grpc . ClientConn { }
}
var err error
@ -77,14 +79,14 @@ func (r *ReactorManager) Connect() *grpc.ClientConn {
if code == ( 5 | 14 ) { // unavailable or not found
to := r . Timeout ( )
if to == 0 {
logging . Debug ( logging . DClient , " Client not responding\n ")
logging . Debug ( logging . DClient , " RMA %v Client not responding", r . Id )
return & grpc . ClientConn { }
}
logging . Debug ( logging . DClient , " Client currently down, retrying in %v ms\n ", to )
logging . Debug ( logging . DClient , " RMA %v Client currently down, retrying in %v ms", r . Id , to )
time . Sleep ( time . Duration ( to ) * time . Millisecond )
} else {
log . Fatal ( "GRPC ERROR: %v" , code )
log ging. Debug ( logging . DError , "RMA %v GRPC ERROR: %v" , r . Id , code )
r . Err <- err
}
}
@ -101,7 +103,7 @@ func (r *ReactorManager) Monitor(conn *grpc.ClientConn) {
resp , err := client . GetReactorStatus ( context . Background ( ) , req )
code := status . Code ( err )
if code != 0 { // if != OK
logging . Debug ( logging . DClient , "R eactor %v down ! Code: %v\n", r . Id , code )
logging . Debug ( logging . DClient , "R MA %v Reactor not responding ! Code: %v\n", r . Id , code )
r . devstatus . Lock ( )
for _ , d := range r . Devs {
newd := d
@ -119,7 +121,7 @@ func (r *ReactorManager) Monitor(conn *grpc.ClientConn) {
r . Devs [ d . Id ] = d
}
r . devstatus . Unlock ( )
logging . Debug ( logging . DPing , " Devices Updated for reactor %v ", r . Id )
logging . Debug ( logging . DPing , " RMA %v Reactor Reached ", r . Id )
time . Sleep ( r . Hb ) // time between sensor pings
}
}