-
Notifications
You must be signed in to change notification settings - Fork 16
/
server.cpp
57 lines (47 loc) · 1.48 KB
/
server.cpp
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
53
54
55
56
57
#include <faabric/endpoint/FaabricEndpoint.h>
#include <faabric/executor/ExecutorFactory.h>
#include <faabric/runner/FaabricMain.h>
#include <faabric/util/logging.h>
using namespace faabric::executor;
class ExampleExecutor : public Executor
{
public:
ExampleExecutor(faabric::Message& msg)
: Executor(msg)
{}
~ExampleExecutor() {}
int32_t executeTask(int threadPoolIdx,
int msgIdx,
std::shared_ptr<faabric::BatchExecuteRequest> req)
{
SPDLOG_INFO("Hello world!");
faabric::Message& msg = req->mutable_messages()->at(msgIdx);
msg.set_outputdata("This is hello output!");
return 0;
}
};
class ExampleExecutorFactory : public ExecutorFactory
{
protected:
std::shared_ptr<Executor> createExecutor(faabric::Message& msg) override
{
return std::make_shared<ExampleExecutor>(msg);
}
};
int main()
{
faabric::util::initLogging();
// Start the worker pool
SPDLOG_INFO("Starting executor pool in the background");
std::shared_ptr<ExecutorFactory> fac =
std::make_shared<ExampleExecutorFactory>();
faabric::runner::FaabricMain m(fac);
m.startBackground();
// Start endpoint, will block until it receives a signal
SPDLOG_INFO("Starting endpoint");
faabric::endpoint::FaabricEndpoint endpoint;
endpoint.start(faabric::endpoint::EndpointMode::SIGNAL);
SPDLOG_INFO("Shutting down endpoint");
m.shutdown();
return EXIT_SUCCESS;
}