feat: Add Jina server health check

- Added a health check to the Jina client to verify server availability.
- Improved error handling and messaging for failed health checks.
- Enhanced client robustness by providing feedback on server status.
This commit is contained in:
Mahmoud Emad
2025-03-12 16:38:38 +02:00
parent a7976c45f9
commit 4abb46b4bf
3 changed files with 30 additions and 1 deletions

View File

@@ -3,6 +3,8 @@
import freeflowuniverse.herolib.clients.jina
mut jina_client := jina.get()!
health := jina_client.health()!
println('Server health: ${health}')
// Create embeddings
embeddings := jina_client.create_embeddings(

View File

@@ -210,3 +210,31 @@ pub fn (mut j Jina) create_embeddings(params CreateEmbeddingParams) !ModelEmbedd
response := httpclient.post_json_str(req)!
return json.decode(ModelEmbeddingOutput, response)!
}
pub struct HealthResponse {
pub mut:
status string
message string
healthy bool
}
pub fn (mut j Jina) health() !HealthResponse {
req := httpconnection.Request{
method: .get
}
mut httpclient := j.httpclient()!
response := httpclient.send(req)!
if response.code == 200 {
return HealthResponse{
status: response.code.str()
message: '200 Service available'
healthy: true
}
}
return HealthResponse{
status: response.code.str()
message: '${response.code} Service Unavailable'
healthy: false
}
}

View File

@@ -2,7 +2,6 @@ module jina
import freeflowuniverse.herolib.core.base
import freeflowuniverse.herolib.core.playbook
import freeflowuniverse.herolib.ui.console
__global (
jina_global map[string]&Jina