New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for basic session management #35
Conversation
include/ppconsul/kv.h
Outdated
} | ||
|
||
class Sessions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's better to make it in the same way as other endpoints:
- Put it into its own file
sessions.h
/sessions.cpp
underppconsul::sessions
namespace. - Constructor takes a reference to
Consul
object rather then toKv
one and other applicable default parameters (token, consistency and DC perhaps?).
include/ppconsul/kv.h
Outdated
} | ||
}; | ||
|
||
// TODO: add ScopedLock |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm?
include/ppconsul/kv.h
Outdated
DELETE, | ||
}; | ||
|
||
struct DestroyError: public ppconsul::Error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you need to have a special exception for a mailformed delete session response?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I just ignore the result?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return parseJsonBool(...)
should be fine. The caller can decide what to do in case of false result (probably nothing).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fun is, it returns true even if called with non-existing session ID. And I have no idea in what situation it returns false, then.
Nevermind, it can fail because of checks and other stuff.
include/ppconsul/kv.h
Outdated
class Sessions | ||
{ | ||
public: | ||
enum class OnInvalidation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extract from class and name InvalidationBehavior
(if placed under sessions
namespace, otherwise SessionInvalidationBehavior
).
include/ppconsul/kv.h
Outdated
public: | ||
enum class OnInvalidation | ||
{ | ||
RELEASE, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't use all capital letters for anything that's not a macro. Use CamelCase
instead.
include/ppconsul/kv.h
Outdated
} | ||
|
||
private: | ||
static std::string encodeBehavior(OnInvalidation behavior) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be moved into cpp.
include/ppconsul/kv.h
Outdated
template<class... Params, class = kwargs::enable_if_kwargs_t<Params...>> | ||
static std::string create(Kv &kv, | ||
const std::string &node = "", int lockDelay = 15, | ||
OnInvalidation behavior = OnInvalidation::RELEASE, int ttl = -1, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lock delay and TTL should both be std::chrono::seconds
.
include/ppconsul/kv.h
Outdated
{ | ||
virtual const char *what() const PPCONSUL_NOEXCEPT override | ||
{ | ||
return "cannot destroy session"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Start with capital letter
OK, addressed all the issues. Please review. |
This looks great, thank you! |
No description provided.