Skip to content

Commit

Permalink
align more blocking methods
Browse files Browse the repository at this point in the history
  • Loading branch information
cedricve committed Jan 11, 2024
1 parent b4369ea commit 49f1603
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
16 changes: 12 additions & 4 deletions machinery/src/components/Kerberos.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,6 @@ func ControlAgent(communication *models.Communication) {
case <-time.After(1 * time.Second):
log.Log.Info("components.Kerberos.ControlAgent(): Restarting machinery because of blocking substream timed out")
}
time.Sleep(2 * time.Second)
occurence = 0
}

Expand All @@ -452,7 +451,6 @@ func ControlAgent(communication *models.Communication) {
case <-time.After(1 * time.Second):
log.Log.Info("components.Kerberos.ControlAgent(): Restarting machinery because of blocking substream timed out")
}
time.Sleep(2 * time.Second)
occurenceSub = 0
}
}
Expand Down Expand Up @@ -589,7 +587,12 @@ func GetDays(c *gin.Context, configDirectory string, configuration *models.Confi
// @Success 200 {object} models.APIResponse
func StopAgent(c *gin.Context, communication *models.Communication) {
log.Log.Info("components.Kerberos.StopAgent(): sending signal to stop agent, this will os.Exit(0).")
communication.HandleBootstrap <- "stop"
select {
case communication.HandleBootstrap <- "stop":
log.Log.Info("components.Kerberos.StopAgent(): Stopping machinery.")
case <-time.After(1 * time.Second):
log.Log.Info("components.Kerberos.StopAgent(): Stopping machinery timed out")
}
c.JSON(200, gin.H{
"stopped": true,
})
Expand All @@ -604,7 +607,12 @@ func StopAgent(c *gin.Context, communication *models.Communication) {
// @Success 200 {object} models.APIResponse
func RestartAgent(c *gin.Context, communication *models.Communication) {
log.Log.Info("components.Kerberos.RestartAgent(): sending signal to restart agent.")
communication.HandleBootstrap <- "restart"
select {
case communication.HandleBootstrap <- "restart":
log.Log.Info("components.Kerberos.RestartAgent(): Restarting machinery.")
case <-time.After(1 * time.Second):
log.Log.Info("components.Kerberos.RestartAgent(): Restarting machinery timed out")
}
c.JSON(200, gin.H{
"restarted": true,
})
Expand Down
4 changes: 3 additions & 1 deletion machinery/src/config/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,9 @@ func SaveConfig(configDirectory string, config models.Config, configuration *mod
if communication.CameraConnected {
select {
case communication.HandleBootstrap <- "restart":
default:
log.Log.Info("config.main.SaveConfig(): update config, restart agent.")
case <-time.After(1 * time.Second):
log.Log.Info("config.main.SaveConfig(): update config, restart agent.")
}
}

Expand Down

0 comments on commit 49f1603

Please sign in to comment.