Skip to content

Commit

Permalink
feat: add pause consumer
Browse files Browse the repository at this point in the history
  • Loading branch information
yordis committed Feb 27, 2024
1 parent 62e12a3 commit 2872b8f
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions lib/gnat/jetstream/api/consumer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,34 @@ defmodule Gnat.Jetstream.API.Consumer do
end
end

@doc """
Pause a consumer until a specific time.
## Examples
iex> {:ok, _response} = Gnat.Jetstream.API.Stream.create(:gnat, %Gnat.Jetstream.API.Stream{name: "astream", subjects: ["subject"]})
iex> {:ok, _response} = Gnat.Jetstream.API.Consumer.create(:gnat, %Gnat.Jetstream.API.Consumer{durable_name: "consumer", stream_name: "astream"})
iex> pause_until = DateTime.add(DateTime.utc_now(), 1, :hour)
iex> Gnat.Jetstream.API.Consumer.pause(:gnat, "astream", "consumer", pause_until)
:ok
"""
@spec pause(
conn :: Gnat.t(),
stream_name :: binary(),
consumer_name :: binary(),
pause_until :: DateTime.t(),
opts :: [domain: nil | binary()]
) ::
:ok | {:error, any()}
def pause(conn, stream_name, consumer_name, pause_until, opts \\ []) do
topic = "#{js_api(opts[:domain])}.CONSUMER.PAUSE.#{stream_name}.#{consumer_name}"
payload = Jason.encode!(%{ pause_until: pause_until })
with {:ok, _response} <- request(conn, topic, payload) do
:ok
end
end

@doc """
Information about the consumer.
Expand Down

0 comments on commit 2872b8f

Please sign in to comment.