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

Added a function to list available buckets #153

Merged
merged 3 commits into from
Apr 17, 2024

Conversation

lsxliron
Copy link

@lsxliron lsxliron commented Apr 9, 2024

Addresses #152

{:ok, conn} = Gnat.start_link()
# {:ok, #PID<0.301.0>}
Gnat.Jetstream.API.KV.list_buckets(conn)
# {:ok, ["bucket1", "bucket2", "bucket3"]}

@mmmries
Copy link
Collaborator

mmmries commented Apr 17, 2024

Thanks @lsxliron for opening this PR! I have a couple of stylistic suggestions here, but no concerns about the functionality or general approach. Would you prefer if i just merged this and just made a few of my own tweaks before releasing, or add my comments inline on the PR and let you make the changes?

@lsxliron
Copy link
Author

Sure thing @mmmries. Please feel free to share your suggestions. I can make changes if needed.

Copy link
Collaborator

@mmmries mmmries left a comment

Choose a reason for hiding this comment

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

I also noticed that the main branch of elixir is showing a bunch of compiler warnings and the latest version of nats server is breaking on some of our unit tests. I'll open a separate PR to address those items, so don't worry about those CI checks here.

"""
@spec list_buckets(conn :: Gnat.t()) :: {:error, term()} | {:ok, list(String.t())}
def list_buckets(conn) do
case Stream.list(conn) do
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would swap this case statement for a with since it has an obvious happy-path pattern.

with {:ok, %{streams: streams}} <- Stream.list(conn) do

case Stream.list(conn) do
{:ok, %{streams: streams}} ->
{:ok,
streams
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would usually build a stream_names = Enum.flat_map(...) on it's own before assembling the {:ok, stream_names} tuple. That avoids extra indentation and is easier to read the flow of the function. This is a subjective opinion for sure, but most of the codebase in this project follows this pattern, so I think it's worth applying here.

* `stream_name` - the stream name to test
"""
@spec is_kv_bucket_stream(stream_name :: binary()) :: boolean()
def is_kv_bucket_stream(stream_name) do
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would suggest moving this function to the KV module. So far I've been keeping all of the KV-specific knowledge in that module and similarly keeping everything related to Object in its own module, so the stream module really just has knowledge of general streams.

I'm definitely open to feedback here if you had a specific reason for putting it into the stream module.

Copy link
Author

Choose a reason for hiding this comment

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

No specific reason other than the fact that it's dealing with the actual stream.
Can definitely be moved to the KV module

@lsxliron lsxliron requested a review from mmmries April 17, 2024 04:52
@mmmries mmmries merged commit bb4c5f0 into nats-io:main Apr 17, 2024
2 checks passed
@mmmries
Copy link
Collaborator

mmmries commented Apr 17, 2024

Thanks for the great contribution and fast changes @lsxliron ❤️💙💜💚💛🧡🤎🖤

I'm going to try to sort out why we're getting different errors on some CI runs with more recent versions of Elixir/NATS and if I can sort that out within a day or two, I'll include any of those fixes in the next release along with your change

@mmmries mmmries mentioned this pull request Apr 17, 2024
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