Skip to content

Commit

Permalink
Moved into a go function for each stream check
Browse files Browse the repository at this point in the history
  • Loading branch information
COMTOP1 committed Feb 20, 2024
1 parent 5fa1db1 commit 70333a1
Showing 1 changed file with 129 additions and 126 deletions.
255 changes: 129 additions & 126 deletions server/views/watchdog.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,147 +31,150 @@ func (v *Views) BeginWatchdog() {
_, fow := v.cache.Get(server.Forwarder.String())

for _, stream := range streams {
transporter := commonTransporter.Transporter{
Action: action.Status,
Unique: stream.Stream,
}

//nolint:staticcheck
fStatus := commonTransporter.ForwarderStatus{
Website: len(stream.Website) > 0,
Streams: len(stream.Streams),
}

var forwarderError, recorderError bool

var wg sync.WaitGroup
wg.Add(2)
stream1 := stream
go func() {
defer wg.Done()
if len(stream.Recording) > 0 && rec {
recorderTransporter := transporter
transporter := commonTransporter.Transporter{
Action: action.Status,
Unique: stream1.Stream,
}

//nolint:staticcheck
fStatus := commonTransporter.ForwarderStatus{
Website: len(stream1.Website) > 0,
Streams: len(stream1.Streams),
}

var forwarderError, recorderError bool

var wg sync.WaitGroup
wg.Add(2)
go func() {
defer wg.Done()
if len(stream1.Recording) > 0 && rec {
recorderTransporter := transporter

var response commonTransporter.ResponseTransporter
response, err = v.wsHelper(server.Recorder, recorderTransporter)
if err != nil {
log.Printf("failed to send or receive message from recorder for status: %+v", err)
recorderError = true
return
}
if response.Status == wsMessages.Error {
log.Printf("failed to get correct response from recorder for status: %s", response.Payload)
recorderError = true
return
}
if response.Status != wsMessages.Okay {
log.Printf("invalid response from recorder for status: %s", response)
recorderError = true
return
}
}
}()
go func() {
defer wg.Done()
if fow {
forwarderTransporter := transporter

forwarderTransporter.Payload = fStatus

var response commonTransporter.ResponseTransporter
response, err = v.wsHelper(server.Forwarder, forwarderTransporter)
if err != nil {
log.Printf("failed to send or receive message from forwarder for status: %+v", err)
forwarderError = true
return
}
if response.Status == wsMessages.Error {
log.Printf("failed to get correct response from forwarder for status: %s", response.Payload)
forwarderError = true
return
}
if response.Status != wsMessages.Okay {
log.Printf("invalid response from recorder for status: %s", response)
forwarderError = true
return
}
}
}()
wg.Wait()

var response commonTransporter.ResponseTransporter
response, err = v.wsHelper(server.Recorder, recorderTransporter)
if recorderError && rec {
stopTransporter := commonTransporter.Transporter{
Action: action.Stop,
Unique: stream1.Stream,
}
var wsResponse commonTransporter.ResponseTransporter
wsResponse, err = v.wsHelper(server.Recorder, stopTransporter)
if err != nil {
log.Printf("failed to send or receive message from recorder for status: %+v", err)
recorderError = true
return
log.Printf("failed sending to Recorder for stop: %+v", err)
}
if response.Status == wsMessages.Error {
log.Printf("failed to get correct response from recorder for status: %s", response.Payload)
recorderError = true
return
if wsResponse.Status == wsMessages.Error {
log.Printf("failed sending to Recorder for stop: %#v", wsResponse)
}
if response.Status != wsMessages.Okay {
log.Printf("invalid response from recorder for status: %s", response)
recorderError = true
return
if wsResponse.Status != wsMessages.Okay {
log.Printf("invalid response from Recorder for stop: %#v", wsResponse)
}
}
}()
go func() {
defer wg.Done()
if fow {
forwarderTransporter := transporter

forwarderTransporter.Payload = fStatus

var response commonTransporter.ResponseTransporter
response, err = v.wsHelper(server.Forwarder, forwarderTransporter)
startTransporter := commonTransporter.Transporter{
Action: action.Start,
Unique: stream1.Stream,
Payload: commonTransporter.RecorderStart{
StreamIn: stream1.Input,
PathOut: stream1.Recording,
},
}
wsResponse, err = v.wsHelper(server.Recorder, startTransporter)
if err != nil {
log.Printf("failed to send or receive message from forwarder for status: %+v", err)
forwarderError = true
return
log.Printf("failed sending to Recorder for start: %+v", err)
}
if response.Status == wsMessages.Error {
log.Printf("failed to get correct response from forwarder for status: %s", response.Payload)
forwarderError = true
return
if wsResponse.Status == wsMessages.Error {
log.Printf("failed sending to Recorder for start: %#v", wsResponse)
}
if response.Status != wsMessages.Okay {
log.Printf("invalid response from recorder for status: %s", response)
forwarderError = true
return
if wsResponse.Status != wsMessages.Okay {
log.Printf("invalid response from Recorder for start: %#v", wsResponse)
}
}
}()
wg.Wait()

if recorderError && rec {
stopTransporter := commonTransporter.Transporter{
Action: action.Stop,
Unique: stream.Stream,
}
var wsResponse commonTransporter.ResponseTransporter
wsResponse, err = v.wsHelper(server.Recorder, stopTransporter)
if err != nil {
log.Printf("failed sending to Recorder for stop: %+v", err)
}
if wsResponse.Status == wsMessages.Error {
log.Printf("failed sending to Recorder for stop: %#v", wsResponse)
}
if wsResponse.Status != wsMessages.Okay {
log.Printf("invalid response from Recorder for stop: %#v", wsResponse)
}

startTransporter := commonTransporter.Transporter{
Action: action.Start,
Unique: stream.Stream,
Payload: commonTransporter.RecorderStart{
StreamIn: stream.Input,
PathOut: stream.Recording,
},
}
wsResponse, err = v.wsHelper(server.Recorder, startTransporter)
if err != nil {
log.Printf("failed sending to Recorder for start: %+v", err)
}
if wsResponse.Status == wsMessages.Error {
log.Printf("failed sending to Recorder for start: %#v", wsResponse)
}
if wsResponse.Status != wsMessages.Okay {
log.Printf("invalid response from Recorder for start: %#v", wsResponse)
}
}

if forwarderError && fow {
stopTransporter := commonTransporter.Transporter{
Action: action.Stop,
Unique: stream.Stream,
}
var wsResponse commonTransporter.ResponseTransporter
wsResponse, err = v.wsHelper(server.Forwarder, stopTransporter)
if err != nil {
log.Printf("failed sending to Forwarder for stop: %+v", err)
}
if wsResponse.Status == wsMessages.Error {
log.Printf("failed sending to Forwarder for stop: %#v", wsResponse)
}
if wsResponse.Status != wsMessages.Okay {
log.Printf("invalid response from Forwarder for stop: %#v", wsResponse)
}
if forwarderError && fow {
stopTransporter := commonTransporter.Transporter{
Action: action.Stop,
Unique: stream1.Stream,
}
var wsResponse commonTransporter.ResponseTransporter
wsResponse, err = v.wsHelper(server.Forwarder, stopTransporter)
if err != nil {
log.Printf("failed sending to Forwarder for stop: %+v", err)
}
if wsResponse.Status == wsMessages.Error {
log.Printf("failed sending to Forwarder for stop: %#v", wsResponse)
}
if wsResponse.Status != wsMessages.Okay {
log.Printf("invalid response from Forwarder for stop: %#v", wsResponse)
}

startTransporter := commonTransporter.Transporter{
Action: action.Start,
Unique: stream.Stream,
Payload: commonTransporter.ForwarderStart{
StreamIn: stream.Input,
WebsiteOut: stream.Website,
Streams: stream.Streams,
},
}
wsResponse, err = v.wsHelper(server.Forwarder, startTransporter)
if err != nil {
log.Printf("failed sending to Forwarder for start: %+v", err)
}
if wsResponse.Status == wsMessages.Error {
log.Printf("failed sending to Forwarder for start: %#v", wsResponse)
}
if wsResponse.Status != wsMessages.Okay {
log.Printf("invalid response from Forwarder for start: %#v", wsResponse)
startTransporter := commonTransporter.Transporter{
Action: action.Start,
Unique: stream1.Stream,
Payload: commonTransporter.ForwarderStart{
StreamIn: stream1.Input,
WebsiteOut: stream1.Website,
Streams: stream1.Streams,
},
}
wsResponse, err = v.wsHelper(server.Forwarder, startTransporter)
if err != nil {
log.Printf("failed sending to Forwarder for start: %+v", err)
}
if wsResponse.Status == wsMessages.Error {
log.Printf("failed sending to Forwarder for start: %#v", wsResponse)
}
if wsResponse.Status != wsMessages.Okay {
log.Printf("invalid response from Forwarder for start: %#v", wsResponse)
}
}
}
}()
}
}
}()
Expand Down

0 comments on commit 70333a1

Please sign in to comment.