Joedb 10.5.0
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
12namespace joedb
13{
14 ////////////////////////////////////////////////////////////////////////////
15 static int push(Arguments &arguments)
16 ////////////////////////////////////////////////////////////////////////////
17 {
18 Parsed_Logger logger(arguments);
19
20 const bool follow = arguments.has_flag("follow");
21 const int64_t until_checkpoint = arguments.get_option<int64_t>
22 (
23 "until",
24 "checkpoint",
25 std::numeric_limits<int64_t>::max()
26 );
27
28 Parsed_Client parsed_client
29 (
30 logger.get(),
33 arguments
34 );
35
36 if (!parsed_client.get())
37 {
38 arguments.print_help(std::cerr) << '\n';
39 parsed_client.print_help(std::cerr);
40 return 1;
41 }
42
43 Client &client = *parsed_client.get();
44 client.push_if_ahead(until_checkpoint);
45
46 if (follow)
47 {
49
50 logger.get().log("joedb_push invoked with --follow: waiting for data");
51
52 while
53 (
54 client.get_connection_checkpoint() < until_checkpoint &&
55 interruptible_sleep(std::chrono::seconds(1))
56 )
57 {
58 client.push_if_ahead(until_checkpoint);
59 }
60 }
61
62 return 0;
63 }
64}
65
66/////////////////////////////////////////////////////////////////////////////
67int main(int argc, char **argv)
68/////////////////////////////////////////////////////////////////////////////
69{
70 return joedb::main_wrapper(joedb::push, argc, argv);
71}
Class for conveniently parsing command-line arguments.
Definition Arguments.h:16
Handle concurrent access to a file with a joedb::Connection.
Definition Client.h:12
virtual int64_t push_if_ahead(int64_t until)=0
static void start()
Definition Signal.cpp:34
int main()
@ read_existing
fails if does not exist
Definition Open_Mode.h:9
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.