Joedb 10.4.3
The Journal-Only Embedded Database
Loading...
Searching...
No Matches
joedb_push.cpp
Go to the documentation of this file.
6#include "joedb/Signal.h"
7
8#include <iostream>
9#include <limits>
10#include <chrono>
11#include <cstring>
12#include <cstdlib>
13
14namespace joedb
15{
16 ////////////////////////////////////////////////////////////////////////////
17 static int push(Arguments &arguments)
18 ////////////////////////////////////////////////////////////////////////////
19 {
20 Parsed_Logger logger(arguments);
21
22 const bool follow = arguments.has_flag("follow");
23 const int64_t until_checkpoint = arguments.get_option<int64_t>
24 (
25 "until",
26 "checkpoint",
27 std::numeric_limits<int64_t>::max()
28 );
29
30 Parsed_Client parsed_client
31 (
32 logger.get(),
35 arguments
36 );
37
38 if (!parsed_client.get())
39 {
40 arguments.print_help(std::cerr) << '\n';
41 parsed_client.print_help(std::cerr);
42 return 1;
43 }
44
45 Client &client = *parsed_client.get();
46 client.push_if_ahead(until_checkpoint);
47
48 if (follow)
49 {
51
52 logger.get().log("joedb_push invoked with --follow: waiting for data");
53
54 while
55 (
56 client.get_connection_checkpoint() < until_checkpoint &&
57 interruptible_sleep(std::chrono::seconds(1))
58 )
59 {
60 client.push_if_ahead(until_checkpoint);
61 }
62 }
63
64 return 0;
65 }
66}
67
68/////////////////////////////////////////////////////////////////////////////
69int main(int argc, char **argv)
70/////////////////////////////////////////////////////////////////////////////
71{
72 return joedb::main_wrapper(joedb::push, argc, argv);
73}
static void start()
Definition Signal.cpp:34
int main()
@ read_existing
fails if does not exist
bool interruptible_sleep(std::chrono::milliseconds duration)
int main_wrapper(int(*main)(Arguments &), int argc, char **argv)
Process command-line arguments and catch exceptions from main.