aboutsummaryrefslogtreecommitdiff
path: root/zenserver/compute/apply.h
blob: 86b2622131aa7ccd84e1c8ffbdb4d55007c7022a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright Epic Games, Inc. All Rights Reserved.

#pragma once

#include <zencore/compactbinary.h>
#include <zencore/iohash.h>
#include <zencore/logging.h>
#include <zenhttp/httpserver.h>

#include <filesystem>
#include <unordered_map>

namespace zen {

class CasStore;
class CidStore;

/**
 * Lambda style compute function service
 */
class HttpFunctionService : public HttpService
{
public:
	HttpFunctionService(CasStore& Store, CidStore& InCidStore, const std::filesystem::path& SandboxBaseDir);
	~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<int>	  m_SandboxCount{0};

	struct WorkerDesc
	{
		CbObject Descriptor;
	};

	[[nodiscard]] std::filesystem::path CreateNewSandbox();
	[[nodiscard]] CbPackage				ExecAction(const WorkerDesc& Worker, CbObject Action);

	RwLock								   m_WorkerLock;
	std::unordered_map<IoHash, WorkerDesc> m_WorkerMap;
};

}  // namespace zen