hiett commited on
Commit
491462f
1 Parent(s): 8155c92

improve and test connection failure logic

Browse files
.gitignore CHANGED
@@ -29,4 +29,6 @@ srh-*.tar
29
 
30
  *.iml
31
 
32
- srh-config/
 
 
 
29
 
30
  *.iml
31
 
32
+ srh-config/
33
+
34
+ test-project/
lib/srh/http/command_handler.ex CHANGED
@@ -73,11 +73,20 @@ defmodule Srh.Http.CommandHandler do
73
  {:ok, result_map} ->
74
  [result_map | responses]
75
 
 
 
 
76
  {:redis_error, result} ->
77
  [result | responses]
78
  end
79
 
80
- dispatch_command_array(rest, connection_info, updated_responses)
 
 
 
 
 
 
81
  end
82
 
83
  defp dispatch_command_array([], _connection_info, responses) do
@@ -113,7 +122,7 @@ defmodule Srh.Http.CommandHandler do
113
  }
114
 
115
  {:error, error} ->
116
- decode_error(error)
117
  end
118
 
119
  Client.return_worker(client_pid, worker_pid)
@@ -122,7 +131,7 @@ defmodule Srh.Http.CommandHandler do
122
  result
123
 
124
  {:error, error} ->
125
- decode_error(error)
126
  end
127
 
128
  {:error, msg} ->
@@ -167,7 +176,7 @@ defmodule Srh.Http.CommandHandler do
167
  {:ok, %{result: res}}
168
 
169
  {:error, error} ->
170
- decode_error(error)
171
  end
172
 
173
  {:error, msg} ->
@@ -176,9 +185,13 @@ defmodule Srh.Http.CommandHandler do
176
  end
177
 
178
  # Figure out if it's an actual Redis error or a Redix error
179
- defp decode_error(error) do
180
  case error do
181
  %{reason: :closed} ->
 
 
 
 
182
  {
183
  :connection_error,
184
  "Unable to connect to the Redis server"
 
73
  {:ok, result_map} ->
74
  [result_map | responses]
75
 
76
+ {:connection_error, result} ->
77
+ {:connection_error, result}
78
+
79
  {:redis_error, result} ->
80
  [result | responses]
81
  end
82
 
83
+ case updated_responses do
84
+ {:connection_error, result} ->
85
+ {:connection_error, result}
86
+
87
+ _ ->
88
+ dispatch_command_array(rest, connection_info, updated_responses)
89
+ end
90
  end
91
 
92
  defp dispatch_command_array([], _connection_info, responses) do
 
122
  }
123
 
124
  {:error, error} ->
125
+ decode_error(error, srh_id)
126
  end
127
 
128
  Client.return_worker(client_pid, worker_pid)
 
131
  result
132
 
133
  {:error, error} ->
134
+ decode_error(error, srh_id)
135
  end
136
 
137
  {:error, msg} ->
 
176
  {:ok, %{result: res}}
177
 
178
  {:error, error} ->
179
+ decode_error(error, srh_id)
180
  end
181
 
182
  {:error, msg} ->
 
185
  end
186
 
187
  # Figure out if it's an actual Redis error or a Redix error
188
+ defp decode_error(error, srh_id) do
189
  case error do
190
  %{reason: :closed} ->
191
+ IO.puts(
192
+ "WARNING: SRH was unable to connect to the Redis server. Please make sure it is running, and the connection information is correct. SRH ID: #{srh_id}"
193
+ )
194
+
195
  {
196
  :connection_error,
197
  "Unable to connect to the Redis server"
lib/srh/http/result_encoder.ex CHANGED
@@ -9,6 +9,10 @@ defmodule Srh.Http.ResultEncoder do
9
  {:redis_error, error_result_map}
10
  end
11
 
 
 
 
 
12
  # List-based responses, they will contain multiple entries
13
  # It's important to note that this is DIFFERENT from a list of values,
14
  # as it's a list of separate command responses. Each is a map that either
 
9
  {:redis_error, error_result_map}
10
  end
11
 
12
+ def encode_response({:connection_error, error_result_map}) do
13
+ {:connection_error, error_result_map}
14
+ end
15
+
16
  # List-based responses, they will contain multiple entries
17
  # It's important to note that this is DIFFERENT from a list of values,
18
  # as it's a list of separate command responses. Each is a map that either