From 49f1603f40c276686349b40310f227b9cb71713d Mon Sep 17 00:00:00 2001 From: Cedric Verstraeten Date: Thu, 11 Jan 2024 22:43:16 +0100 Subject: [PATCH] align more blocking methods --- machinery/src/components/Kerberos.go | 16 ++++++++++++---- machinery/src/config/main.go | 4 +++- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/machinery/src/components/Kerberos.go b/machinery/src/components/Kerberos.go index dd3a37f..d9cc663 100644 --- a/machinery/src/components/Kerberos.go +++ b/machinery/src/components/Kerberos.go @@ -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 } @@ -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 } } @@ -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, }) @@ -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, }) diff --git a/machinery/src/config/main.go b/machinery/src/config/main.go index 56278fd..f822929 100644 --- a/machinery/src/config/main.go +++ b/machinery/src/config/main.go @@ -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.") } }