From 4abb46b4bf65ea07a8f48303b613f0fec70e1c6e Mon Sep 17 00:00:00 2001 From: Mahmoud Emad Date: Wed, 12 Mar 2025 16:38:38 +0200 Subject: [PATCH] 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. --- examples/clients/jina.vsh | 2 ++ lib/clients/jina/embeddings_api.v | 28 ++++++++++++++++++++++++++++ lib/clients/jina/jina_factory_.v | 1 - 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/examples/clients/jina.vsh b/examples/clients/jina.vsh index 7986a567..ea430db1 100755 --- a/examples/clients/jina.vsh +++ b/examples/clients/jina.vsh @@ -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( diff --git a/lib/clients/jina/embeddings_api.v b/lib/clients/jina/embeddings_api.v index 73fb76d9..8cf61dbe 100644 --- a/lib/clients/jina/embeddings_api.v +++ b/lib/clients/jina/embeddings_api.v @@ -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 + } +} diff --git a/lib/clients/jina/jina_factory_.v b/lib/clients/jina/jina_factory_.v index 6a602a57..e738e5ac 100644 --- a/lib/clients/jina/jina_factory_.v +++ b/lib/clients/jina/jina_factory_.v @@ -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