From 013e2c7ab88dc51d92d683e8f8ec488bdb4d08d9 Mon Sep 17 00:00:00 2001 From: Joe Kirchoff Date: Tue, 3 May 2022 15:57:02 -0700 Subject: Initialize upstream apply in background thread (#88) --- zenserver/compute/function.cpp | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'zenserver/compute/function.cpp') diff --git a/zenserver/compute/function.cpp b/zenserver/compute/function.cpp index dd31013ef..171c67a6e 100644 --- a/zenserver/compute/function.cpp +++ b/zenserver/compute/function.cpp @@ -39,15 +39,17 @@ HttpFunctionService::HttpFunctionService(CasStore& Store, { m_UpstreamApply = UpstreamApply::Create({}, m_CasStore, m_CidStore); - auto HordeUpstreamEndpoint = UpstreamApplyEndpoint::CreateHordeEndpoint(ComputeOptions, - ComputeAuthConfig, - StorageOptions, - StorageAuthConfig, - m_CasStore, - m_CidStore, - Mgr); - m_UpstreamApply->RegisterEndpoint(std::move(HordeUpstreamEndpoint)); - m_UpstreamApply->Initialize(); + InitializeThread = std::thread{[this, ComputeOptions, StorageOptions, ComputeAuthConfig, StorageAuthConfig, &Mgr] { + auto HordeUpstreamEndpoint = UpstreamApplyEndpoint::CreateHordeEndpoint(ComputeOptions, + ComputeAuthConfig, + StorageOptions, + StorageAuthConfig, + m_CasStore, + m_CidStore, + Mgr); + m_UpstreamApply->RegisterEndpoint(std::move(HordeUpstreamEndpoint)); + m_UpstreamApply->Initialize(); + }}; m_Router.AddPattern("job", "([[:digit:]]+)"); m_Router.AddPattern("worker", "([[:xdigit:]]{40})"); @@ -58,8 +60,7 @@ HttpFunctionService::HttpFunctionService(CasStore& Store, [this](HttpRouterRequest& Req) { HttpServerRequest& HttpReq = Req.ServerRequest(); - // Todo: check upstream health - return HttpReq.WriteResponse(HttpResponseCode::OK); + return HttpReq.WriteResponse(m_UpstreamApply->IsHealthy() ? HttpResponseCode::OK : HttpResponseCode::ServiceUnavailable); }, HttpVerb::kGet); -- cgit v1.2.3