Joedb 10.3.0
The Journal-Only Embedded Database
Loading...
Searching...
No Matches
joedb_push.cpp
Go to the documentation of this file.
5#include "joedb/Signal.h"
6
7#include <iostream>
8#include <limits>
9#include <thread>
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 Client_Parser client_parser
31 (
32 logger.get(),
35 arguments
36 );
37
38 if (!client_parser.get())
39 {
40 arguments.print_help(std::cerr) << '\n';
41 client_parser.print_help(std::cerr);
42 return 1;
43 }
44
45 Client &client = *client_parser.get();
46 client.push_if_ahead(until_checkpoint);
47
48 if (follow)
49 {
51
52 while
53 (
54 client.get_connection_checkpoint() < until_checkpoint &&
55 Signal::get_signal() != SIGINT
56 )
57 {
58 std::this_thread::sleep_for(std::chrono::seconds(1));
59 client.push_if_ahead(until_checkpoint);
60 }
61 }
62
63 return 0;
64 }
65}
66
67/////////////////////////////////////////////////////////////////////////////
68int main(int argc, char **argv)
69/////////////////////////////////////////////////////////////////////////////
70{
71 return joedb::main_wrapper(joedb::push, argc, argv);
72}
static int get_signal()
Definition Signal.cpp:27
static void start()
Definition Signal.cpp:34
int main()
@ read_existing
fails if does not exist
int main_wrapper(int(*main)(Arguments &), int argc, char **argv)
Process command-line arguments and catch exceptions from main.