Closed yunkon-kim closed 2 years ago
errgroup?
Package errgroup provides synchronization, error propagation, and Context cancelation for groups of goroutines working on subtasks of a common task. - errgroup - go.pkg.dev
Good example (I think)
~Practices (ongoing)~ ~- errgroup for graceful shutdown~ ~- A skeleton for remote control~ ~ - Note: It's simply classified as to control module and process module.~
The following link provides a skeleton for remote control. - A skeleton for remote control
It provides:
signal
package,func main() {
fmt.Println("Start")
var wg sync.WaitGroup
// A context for graceful shutdown (It is based on the signal package)
//
// NOTE
// Use os.Interrupt to gracefully shutdown on Ctrl+C which is SIGINT
// Use syscall.SIGTERM which is the usual signal for termination and
// the default one (it can be modified) for docker containers, which is also used by kubernetes.
gracefulShutdownContext, stop := signal.NotifyContext(context.TODO(), os.Interrupt, syscall.SIGTERM)
defer stop()
go func() {
<-gracefulShutdownContext.Done()
fmt.Println("Tasks before shutting down")
// Add additional tasks here
stop()
}()
command := make(chan string)
// Process section
wg.Add(1)
go process(command, gracefulShutdownContext, &wg)
// Control section
wg.Add(1)
go control(command, gracefulShutdownContext, &wg)
fmt.Printf("Wait until go routines are finished.\n")
wg.Wait()
fmt.Println("Main done")
}
From now on I think I need to improve many parts of the cbnet
package and cb-network agent
:sweat_smile:
References:
What would you like to be added : I'd like to control cb-network agents remotely.
Why is this needed : It's needed for an admin to control the agents remotely.
Tasks (expected)
Concept![image](https://user-images.githubusercontent.com/7975459/147902981-380352b1-82db-4077-9a99-8580ab538818.png)