Skip to content

Commit 93101b4

Browse files
committed
#106: work in progress: removed compiler warnings
1 parent 47d3a90 commit 93101b4

File tree

3 files changed

+42
-11
lines changed

3 files changed

+42
-11
lines changed

lib/mongo.ex

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -827,33 +827,64 @@ defmodule Mongo do
827827
end
828828
end
829829

830+
##
831+
# Checks for an error and broadcast the event.
832+
##
833+
defp check_for_error({%{"ok" => ok} = response, %{request_id: request_id, operation_id: operation_id, connection_id: connection_id} = event, flags, duration}) when ok == 1 do
834+
Events.notify(
835+
%CommandSucceededEvent{
836+
reply: response,
837+
duration: duration,
838+
command_name: event.command_name,
839+
request_id: request_id,
840+
operation_id: operation_id,
841+
connection_id: connection_id
842+
},
843+
:commands
844+
)
845+
846+
{:ok, {flags, response}}
847+
end
848+
830849
defp check_for_error({%{"ok" => ok} = response, event, flags, duration}) when ok == 1 do
831850
Events.notify(
832851
%CommandSucceededEvent{
833852
reply: response,
834853
duration: duration,
835-
command_name: event.command_name, ## todo
836-
#request_id: event.request_id,
837-
#operation_id: event.operation_id,
838-
#connection_id: event.connection_id
854+
command_name: event.command_name
839855
},
840856
:commands
841857
)
842858

843859
{:ok, {flags, response}}
844860
end
845861

846-
defp check_for_error({doc, event, _flags, duration}) do
862+
defp check_for_error({doc, %{request_id: request_id, operation_id: operation_id, connection_id: connection_id} = event, _flags, duration}) do
847863
error = Mongo.Error.exception(doc)
848864

849865
Events.notify(
850866
%CommandFailedEvent{
851867
failure: error,
852868
duration: duration,
853869
command_name: event.command_name,
854-
#request_id: event.request_id,
855-
#operation_id: event.operation_id,
856-
#connection_id: event.connection_id
870+
request_id: request_id,
871+
operation_id: operation_id,
872+
connection_id: connection_id
873+
},
874+
:commands
875+
)
876+
877+
{:error, error}
878+
end
879+
880+
defp check_for_error({doc, event, _flags, duration}) do
881+
error = Mongo.Error.exception(doc)
882+
883+
Events.notify(
884+
%CommandFailedEvent{
885+
failure: error,
886+
duration: duration,
887+
command_name: event.command_name
857888
},
858889
:commands
859890
)

lib/mongo/monitor.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,8 @@ defmodule Mongo.Monitor do
196196
##
197197
# Starts the streaming mode
198198
##
199-
defp start_streaming_mode(%{address: address, topology_pid: topology_pid, heartbeat_frequency_ms: heartbeat_frequency_ms, opts: opts} = state, _server_description) do
200-
args = [topology_pid, address, heartbeat_frequency_ms, opts]
199+
defp start_streaming_mode(%{address: address, topology_pid: topology_pid, opts: opts} = state, _server_description) do
200+
args = [topology_pid, address, opts]
201201
with {:ok, pid} <- StreamingHelloMonitor.start_link(args) do
202202
## debug info("Starting streaming mode")
203203
%{state | mode: :streaming_mode, streaming_pid: pid, heartbeat_frequency_ms: 10_000}

lib/mongo/streaming_hello_monitor.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ defmodule Mongo.StreamingHelloMonitor do
3030
@doc """
3131
Initialize the monitor process
3232
"""
33-
def init([topology_pid, address, heartbeat_frequency_ms, opts]) do
33+
def init([topology_pid, address, opts]) do
3434

3535
heartbeat_frequency_ms = 10_000
3636

0 commit comments

Comments
 (0)