// Copyright Epic Games, Inc. All Rights Reserved. #pragma once #include #if !defined(ZEN_WITH_COMPUTE_SERVICES) # define ZEN_WITH_COMPUTE_SERVICES ZEN_PLATFORM_WINDOWS #endif #if ZEN_WITH_COMPUTE_SERVICES # include # include # include # include # include # include namespace zen { class CasStore; class CidStore; class UpstreamApply; class CloudCacheClient; class AuthMgr; struct UpstreamAuthConfig; struct CloudCacheClientOptions; /** * Lambda style compute function service */ class HttpFunctionService : public HttpService { public: HttpFunctionService(CasStore& Store, CidStore& InCidStore, const std::filesystem::path& BaseDir, const CloudCacheClientOptions& ComputeOptions, const CloudCacheClientOptions& StorageOptions, const UpstreamAuthConfig& ComputeAuthConfig, const UpstreamAuthConfig& StorageAuthConfig, AuthMgr& Mgr); ~HttpFunctionService(); virtual const char* BaseUri() const override; virtual void HandleRequest(HttpServerRequest& Request) override; private: spdlog::logger& Log() { return m_Log; } spdlog::logger& m_Log; HttpRequestRouter m_Router; CasStore& m_CasStore; CidStore& m_CidStore; std::filesystem::path m_SandboxPath; std::filesystem::path m_FunctionPath; std::atomic m_SandboxCount{0}; std::unique_ptr m_UpstreamApply; struct WorkerDesc { CbObject Descriptor; }; [[nodiscard]] std::filesystem::path CreateNewSandbox(); [[nodiscard]] CbPackage ExecAction(const WorkerDesc& Worker, CbObject Action); [[nodiscard]] HttpResponseCode ExecActionUpstream(const WorkerDesc& Worker, CbObject Action, CbObject& Object); [[nodiscard]] HttpResponseCode ExecActionUpstreamResult(const IoHash& WorkerId, const IoHash& ActionId, CbPackage& Package); RwLock m_WorkerLock; std::unordered_map m_WorkerMap; }; } // namespace zen #endif // ZEN_WITH_COMPUTE_SERVICES