mirror of
https://github.com/hoytech/strfry.git
synced 2025-06-17 08:48:51 +00:00

- It is now up to the caller to do so - QueryScheduler now can optionally not bother to ensure that the events are fresh
50 lines
1.1 KiB
C++
50 lines
1.1 KiB
C++
#include <iostream>
|
|
|
|
#include <docopt.h>
|
|
#include "golpe.h"
|
|
|
|
#include "DBQuery.h"
|
|
#include "events.h"
|
|
|
|
|
|
static const char USAGE[] =
|
|
R"(
|
|
Usage:
|
|
scan [--pause=<pause>] [--metrics] [--count] <filter>
|
|
)";
|
|
|
|
|
|
void cmd_scan(const std::vector<std::string> &subArgs) {
|
|
std::map<std::string, docopt::value> args = docopt::docopt(USAGE, subArgs, true, "");
|
|
|
|
uint64_t pause = 0;
|
|
if (args["--pause"]) pause = args["--pause"].asLong();
|
|
|
|
bool metrics = args["--metrics"].asBool();
|
|
bool count = args["--count"].asBool();
|
|
|
|
std::string filterStr = args["<filter>"].asString();
|
|
|
|
|
|
DBQuery query(tao::json::from_string(filterStr));
|
|
|
|
Decompressor decomp;
|
|
|
|
auto txn = env.txn_ro();
|
|
|
|
uint64_t numEvents = 0;
|
|
|
|
exitOnSigPipe();
|
|
|
|
while (1) {
|
|
bool complete = query.process(txn, [&](const auto &sub, uint64_t levId){
|
|
if (count) numEvents++;
|
|
else std::cout << getEventJson(txn, decomp, levId) << "\n";
|
|
}, pause ? pause : MAX_U64, metrics);
|
|
|
|
if (complete) break;
|
|
}
|
|
|
|
if (count) std::cout << numEvents << std::endl;
|
|
}
|