Skip to content
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

Merged
merged 1 commit into from Jun 11, 2019
Merged

Conversation

shdown
Copy link
Contributor

@shdown shdown commented Jun 6, 2019

No description provided.

}

class Sessions
Copy link
Owner

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 under ppconsul::sessions namespace.
  • Constructor takes a reference to Consul object rather then to Kv one and other applicable default parameters (token, consistency and DC perhaps?).

}
};

// TODO: add ScopedLock
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm?

DELETE,
};

struct DestroyError: public ppconsul::Error
Copy link
Owner

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?

Copy link
Contributor Author

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?

Copy link
Owner

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).

Copy link
Contributor Author

@shdown shdown Jun 9, 2019

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.

class Sessions
{
public:
enum class OnInvalidation
Copy link
Owner

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).

public:
enum class OnInvalidation
{
RELEASE,
Copy link
Owner

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.

}

private:
static std::string encodeBehavior(OnInvalidation behavior)
Copy link
Owner

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.

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,
Copy link
Owner

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.

{
virtual const char *what() const PPCONSUL_NOEXCEPT override
{
return "cannot destroy session";
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Start with capital letter

@shdown
Copy link
Contributor Author

shdown commented Jun 9, 2019

OK, addressed all the issues. Please review.

@oliora oliora merged commit fd3a22e into oliora:master Jun 11, 2019
@oliora
Copy link
Owner

oliora commented Jun 11, 2019

This looks great, thank you!

@shdown shdown deleted the sessions branch June 12, 2019 09:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants