nanoMMO 0.97.8
Building an MMO: The Engineering Series
Loading...
Searching...
No Matches
recorder.h
Go to the documentation of this file.
1#ifndef NANOMMO_SERVER_RECORDER_H_
2#define NANOMMO_SERVER_RECORDER_H_
3
4#include <chrono>
5#include <functional>
6#include <string>
7#include <string_view>
8
9#include "absl/status/status.h"
10#include "absl/status/statusor.h"
11#include "server/redis.h"
12
13namespace nanommo {
14
15/// Takes the game's events from the Redis stream the worlds add them to, a
16/// batch at a time, to the sink, which puts them into ClickHouse.
17class Recorder {
18 public:
19 /// Stores a batch of rows, one a line, or says why it couldn't.
20 using Sink = std::function<absl::Status(std::string_view rows)>;
21
22 /// The consumer group the recorders read the stream as. Redis gives each
23 /// entry to one consumer of the group, and remembers which it's given out
24 /// and not had acknowledged.
25 static constexpr char kGroup[] = "recorder";
26
27 /// The most rows a batch takes.
28 static constexpr int kBatch = 10'000;
29
30 /// Waits up to wait each time for events to come, as the consumer.
31 Recorder(Redis& redis, std::string consumer, Sink sink,
32 std::chrono::milliseconds wait = std::chrono::seconds(1));
33
34 /// Records a batch: first what it took before and couldn't store, then
35 /// what's new. Returns how many it stored.
36 absl::StatusOr<int> Record();
37
38 private:
39 Redis& redis_;
40 std::string consumer_;
41 Sink sink_;
42 std::chrono::milliseconds wait_;
43 bool grouped_ = false;
44 /// Whether to look at what it took before first.
45 bool pending_ = true;
46};
47
48} // namespace nanommo
49
50#endif // NANOMMO_SERVER_RECORDER_H_
absl::StatusOr< int > Record()
Definition recorder.cc:20
static constexpr char kGroup[]
Definition recorder.h:25
std::function< absl::Status(std::string_view rows)> Sink
Stores a batch of rows, one a line, or says why it couldn't.
Definition recorder.h:20
Recorder(Redis &redis, std::string consumer, Sink sink, std::chrono::milliseconds wait=std::chrono::seconds(1))
Waits up to wait each time for events to come, as the consumer.
Definition recorder.cc:13
static constexpr int kBatch
The most rows a batch takes.
Definition recorder.h:28
Definition chat.cc:9