feat: return error on grpc connection error
This commit is contained in:
		
							parent
							
								
									2237ce41eb
								
							
						
					
					
						commit
						0ee77561be
					
				|  | @ -16,8 +16,12 @@ type Sandbox struct { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (e *Sandbox) Run(cmds []stage.Cmd) ([]stage.ExecutorResult, error) { | func (e *Sandbox) Run(cmds []stage.Cmd) ([]stage.ExecutorResult, error) { | ||||||
|  | 	var err error | ||||||
| 	if e.execClient == nil { | 	if e.execClient == nil { | ||||||
| 		e.execClient = createExecClient(e.execServer, e.token) | 		e.execClient, err = createExecClient(e.execServer, e.token) | ||||||
|  | 		if err != nil { | ||||||
|  | 			return nil, err | ||||||
|  | 		} | ||||||
| 	} | 	} | ||||||
| 	// cannot use range loop since we need to change the value
 | 	// cannot use range loop since we need to change the value
 | ||||||
| 	for i := 0; i < len(cmds); i++ { | 	for i := 0; i < len(cmds); i++ { | ||||||
|  |  | ||||||
|  | @ -3,7 +3,6 @@ package sandbox | ||||||
| import ( | import ( | ||||||
| 	"context" | 	"context" | ||||||
| 	"log/slog" | 	"log/slog" | ||||||
| 	"os" |  | ||||||
| 
 | 
 | ||||||
| 	"github.com/criyle/go-judge/pb" | 	"github.com/criyle/go-judge/pb" | ||||||
| 	"google.golang.org/grpc" | 	"google.golang.org/grpc" | ||||||
|  | @ -12,13 +11,13 @@ import ( | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| // copied from https://github.com/criyle/go-judger-demo/blob/master/apigateway/main.go
 | // copied from https://github.com/criyle/go-judger-demo/blob/master/apigateway/main.go
 | ||||||
| func createExecClient(execServer, token string) pb.ExecutorClient { | func createExecClient(execServer, token string) (pb.ExecutorClient, error) { | ||||||
| 	conn, err := createGRPCConnection(execServer, token) | 	conn, err := createGRPCConnection(execServer, token) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		slog.Error("gRPC connection", "error", err) | 		slog.Error("gRPC connection", "error", err) | ||||||
| 		os.Exit(1) | 		return nil, err | ||||||
| 	} | 	} | ||||||
| 	return pb.NewExecutorClient(conn) | 	return pb.NewExecutorClient(conn), nil | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func createGRPCConnection(addr, token string) (*grpc.ClientConn, error) { | func createGRPCConnection(addr, token string) (*grpc.ClientConn, error) { | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user