mirror of
https://github.com/crawlab-team/crawlab.git
synced 2026-01-22 17:31:03 +01:00
- Added WaitForReady method to GrpcClient for blocking until the client is ready. - Updated WorkerService to utilize WaitForReady for ensuring gRPC client readiness before starting. - Refactored ModelService to consistently use GetGrpcClient for context management. - Changed logging level for received metrics in MetricServiceServer from Info to Debug. - Modified error handling in HandleError to conditionally print errors based on the environment. - Cleaned up unused GrpcClient references in various services, improving code clarity.
44 lines
878 B
Go
44 lines
878 B
Go
package server
|
|
|
|
import (
|
|
"encoding/json"
|
|
"github.com/crawlab-team/crawlab/core/utils"
|
|
"github.com/crawlab-team/crawlab/grpc"
|
|
"github.com/crawlab-team/crawlab/trace"
|
|
)
|
|
|
|
func HandleError(err error) (res *grpc.Response, err2 error) {
|
|
if utils.IsDev() {
|
|
trace.PrintError(err)
|
|
}
|
|
return &grpc.Response{
|
|
Code: grpc.ResponseCode_ERROR,
|
|
Error: err.Error(),
|
|
}, err
|
|
}
|
|
|
|
func HandleSuccess() (res *grpc.Response, err error) {
|
|
return &grpc.Response{
|
|
Code: grpc.ResponseCode_OK,
|
|
Message: "success",
|
|
}, nil
|
|
}
|
|
|
|
func HandleSuccessWithData(data interface{}) (res *grpc.Response, err error) {
|
|
var bytes []byte
|
|
switch data.(type) {
|
|
case []byte:
|
|
bytes = data.([]byte)
|
|
default:
|
|
bytes, err = json.Marshal(data)
|
|
if err != nil {
|
|
return HandleError(err)
|
|
}
|
|
}
|
|
return &grpc.Response{
|
|
Code: grpc.ResponseCode_OK,
|
|
Message: "success",
|
|
Data: bytes,
|
|
}, nil
|
|
}
|