Skip to content

Commit

Permalink
Don't pass message function to logger calls
Browse files Browse the repository at this point in the history
  • Loading branch information
slashdotdash committed Jan 9, 2024
1 parent d9fd07a commit 5d8b366
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 42 deletions.
24 changes: 12 additions & 12 deletions lib/event_store/storage/delete_stream.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@ defmodule EventStore.Storage.DeleteStream do

case Postgrex.query(conn, query, [stream_id], opts) do
{:ok, %Postgrex.Result{num_rows: 1}} ->
Logger.debug(fn -> "Soft deleted stream #{inspect(stream_id)}" end)
Logger.debug("Soft deleted stream #{inspect(stream_id)}")

:ok

{:ok, %Postgrex.Result{num_rows: 0}} ->
Logger.warning(fn ->
Logger.warning(
"Failed to soft delete stream #{inspect(stream_id)} due to: stream not found"
end)
)

{:error, :stream_not_found}

{:error, error} = reply ->
Logger.warning(fn ->
Logger.warning(
"Failed to soft delete stream #{inspect(stream_id)} due to: " <> inspect(error)
end)
)

reply
end
Expand All @@ -39,28 +39,28 @@ defmodule EventStore.Storage.DeleteStream do

case Postgrex.query(conn, query, [stream_id], opts) do
{:ok, %Postgrex.Result{num_rows: 1, rows: [[^stream_id]]}} ->
Logger.debug(fn -> "Hard deleted stream #{inspect(stream_id)}" end)
Logger.debug("Hard deleted stream #{inspect(stream_id)}")

:ok

{:ok, %Postgrex.Result{num_rows: 0}} ->
Logger.warning(fn ->
Logger.warning(
"Failed to hard delete stream #{inspect(stream_id)} due to: stream not found"
end)
)

{:error, :stream_not_found}

{:error, %Postgrex.Error{postgres: %{code: :feature_not_supported}} = error} ->
Logger.warning(fn ->
Logger.warning(
"Failed to hard delete stream #{inspect(stream_id)} due to: " <> inspect(error)
end)
)

{:error, :not_supported}

{:error, error} = reply ->
Logger.warning(fn ->
Logger.warning(
"Failed to hard delete stream #{inspect(stream_id)} due to: " <> inspect(error)
end)
)

reply
end
Expand Down
4 changes: 1 addition & 3 deletions lib/event_store/storage/reader.ex
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ defmodule EventStore.Storage.Reader do
end

defp failed_to_read(stream_id, reason) do
Logger.warning(fn ->
"Failed to read events from stream id #{stream_id} due to: #{inspect(reason)}"
end)
Logger.warning("Failed to read events from stream id #{stream_id} due to: #{inspect(reason)}")

{:error, reason}
end
Expand Down
4 changes: 2 additions & 2 deletions lib/event_store/storage/snapshot.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ defmodule EventStore.Storage.Snapshot do
{:ok, to_snapshot_from_row(row)}

{:error, error} = reply ->
Logger.warning(fn ->
Logger.warning(
"Failed to read snapshot for source \"#{source_uuid}\" due to: #{inspect(error)}"
end)
)

reply
end
Expand Down
38 changes: 22 additions & 16 deletions lib/event_store/storage/subscription.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ defmodule EventStore.Storage.Subscription do
alias EventStore.Sql.Statements
alias EventStore.Storage.Subscription

alias EventStore.Storage.Subscription.{
CreateSubscription,
QueryAllSubscriptions,
QuerySubscription
}

@type t :: %EventStore.Storage.Subscription{
subscription_id: non_neg_integer(),
stream_uuid: String.t(),
Expand All @@ -16,21 +22,21 @@ defmodule EventStore.Storage.Subscription do

defstruct [:subscription_id, :stream_uuid, :subscription_name, :last_seen, :created_at]

defdelegate subscriptions(conn, opts), to: Subscription.All, as: :execute
defdelegate subscriptions(conn, opts), to: QueryAllSubscriptions, as: :execute

defdelegate subscription(conn, stream_uuid, subscription_name, opts),
to: Subscription.Query,
to: QuerySubscription,
as: :execute

def subscribe_to_stream(conn, stream_uuid, subscription_name, start_from, opts) do
with {:ok, %Subscription{} = subscription} <-
Subscription.Query.execute(conn, stream_uuid, subscription_name, opts) do
{:ok, subscription}
else
case QuerySubscription.execute(conn, stream_uuid, subscription_name, opts) do
{:ok, %Subscription{}} = reply ->
reply

{:error, :subscription_not_found} ->
create_subscription(conn, stream_uuid, subscription_name, start_from, opts)

reply ->
{:error, _error} = reply ->
reply
end
end
Expand All @@ -43,19 +49,19 @@ defmodule EventStore.Storage.Subscription do
do: Subscription.Delete.execute(conn, stream_uuid, subscription_name, opts)

defp create_subscription(conn, stream_uuid, subscription_name, start_from, opts) do
with {:ok, %Subscription{} = subscription} <-
Subscription.Subscribe.execute(conn, stream_uuid, subscription_name, start_from, opts) do
{:ok, subscription}
else
case CreateSubscription.execute(conn, stream_uuid, subscription_name, start_from, opts) do
{:ok, %Subscription{}} = reply ->
reply

{:error, :subscription_already_exists} ->
Subscription.Query.execute(conn, stream_uuid, subscription_name, opts)
QuerySubscription.execute(conn, stream_uuid, subscription_name, opts)

reply ->
{:error, _error} = reply ->
reply
end
end

defmodule All do
defmodule QueryAllSubscriptions do
@moduledoc false

def execute(conn, opts) do
Expand All @@ -71,7 +77,7 @@ defmodule EventStore.Storage.Subscription do
end
end

defmodule Query do
defmodule QuerySubscription do
@moduledoc false

def execute(conn, stream_uuid, subscription_name, opts) do
Expand All @@ -87,7 +93,7 @@ defmodule EventStore.Storage.Subscription do
end
end

defmodule Subscribe do
defmodule CreateSubscription do
@moduledoc false

def execute(conn, stream_uuid, subscription_name, start_from, opts) do
Expand Down
10 changes: 3 additions & 7 deletions lib/event_store/subscriptions/subscription_fsm.ex
Original file line number Diff line number Diff line change
Expand Up @@ -134,23 +134,19 @@ defmodule EventStore.Subscriptions.SubscriptionFsm do

case first_event_number(events) do
past when past < expected_event ->
Logger.debug(fn -> describe(data) <> " received past event(s), ignoring" end)
Logger.debug(describe(data) <> " received past event(s), ignoring")

# Ignore already seen events
next_state(:subscribed, data)

future when future > expected_event ->
Logger.debug(fn ->
describe(data) <> " received unexpected event(s), requesting catch up"
end)
Logger.debug(describe(data) <> " received unexpected event(s), requesting catch up")

# Missed event(s), request catch-up with any unseen events from storage
next_state(:request_catch_up, data)

^expected_event ->
Logger.debug(fn ->
describe(data) <> " is enqueueing #{length(events)} event(s)"
end)
Logger.debug(describe(data) <> " is enqueueing #{length(events)} event(s)")

# Subscriber is up-to-date, so enqueue events to send
data =
Expand Down
4 changes: 2 additions & 2 deletions test/manual/long_running_subscription.exs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ defmodule LoggingSubscriber do
end

def handle_info({:subscribed, subscription}, subscription) do
Logger.debug(fn -> "Subscribed to stream" end)
Logger.debug("Subscribed to stream")

{:noreply, subscription}
end

def handle_info({:events, events}, subscription) do
Logger.debug(fn -> "Received event(s): #{inspect(events)}" end)
Logger.debug("Received event(s): #{inspect(events)}")

:ok = EventStore.ack(subscription, events)

Expand Down

0 comments on commit 5d8b366

Please sign in to comment.