feat: enhance gRPC client with state management and reconnection logic

- Introduced state management in GrpcClient to monitor and handle connection states effectively.
- Added a reconnect channel and a state monitoring goroutine to facilitate automatic reconnections on state changes.
- Updated the connect method to initiate a reconnection loop upon connection loss.
- Enhanced logging for connection state changes and errors during connection attempts.
- Refactored tests to ensure proper initialization of gRPC client and server, improving test reliability and coverage.
This commit is contained in:
Marvin Zhang
2024-12-21 21:41:00 +08:00
parent 75da4fff0f
commit 29af5a366b
3 changed files with 374 additions and 283 deletions

View File

@@ -75,14 +75,14 @@ type Runner struct {
// Init initializes the task runner by updating the task status and establishing gRPC connections
func (r *Runner) Init() (err error) {
// wait for grpc client ready
client2.GetGrpcClient().WaitForReady()
// update task
if err := r.updateTask("", nil); err != nil {
return err
}
// wait for grpc client ready
client2.GetGrpcClient().WaitForReady()
// grpc task service stream client
if err := r.initConnection(); err != nil {
return err