forked from heavyai/heavydb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathThriftOps.h
50 lines (43 loc) · 1.34 KB
/
ThriftOps.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#ifndef THRIFTOPS_H
#define THRIFTOPS_H
#include "ThriftService.h"
#include "ThriftWithRetry.h"
namespace {
struct DoNothing {
template <typename... T>
void operator()(T&&... t) {}
};
} // namespace
template <ThriftService THRIFT_SERVICE,
typename CONTEXT_TYPE,
typename ON_SUCCESS_LAMBDA = DoNothing,
typename ON_FAIL_LAMBDA = DoNothing>
bool thrift_op(CONTEXT_TYPE& context,
ON_SUCCESS_LAMBDA success_op = ON_SUCCESS_LAMBDA(),
ON_FAIL_LAMBDA fail_op = ON_FAIL_LAMBDA(),
int const try_count = 1) {
if (thrift_with_retry(THRIFT_SERVICE, context, nullptr, try_count)) {
success_op(context);
return true;
}
fail_op(context);
return false;
}
template <ThriftService THRIFT_SERVICE,
typename CONTEXT_TYPE,
typename ON_SUCCESS_LAMBDA = DoNothing,
typename ON_FAIL_LAMBDA = DoNothing>
bool thrift_op(CONTEXT_TYPE& context,
char const* arg,
ON_SUCCESS_LAMBDA success_op = ON_SUCCESS_LAMBDA(),
ON_FAIL_LAMBDA fail_op = ON_FAIL_LAMBDA(),
int const try_count = 1) {
if (thrift_with_retry(THRIFT_SERVICE, context, arg, try_count)) {
thrift_with_retry(kGET_SERVER_STATUS, context, nullptr);
success_op(context);
return true;
}
fail_op(context);
return false;
}
#endif