Skip to content

Commit 73a1af7

Browse files
authored
Merge pull request wistia#5 from edennis/fix-warnings-for-1.4
Fix warnings for 1.4
2 parents bb3d839 + 35ec9f7 commit 73a1af7

File tree

13 files changed

+74
-74
lines changed

13 files changed

+74
-74
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
/deps
44
erl_crash.dump
55
*.ez
6+
test/data_paths

lib/nsq/conn_info.ex

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ defmodule NSQ.ConnInfo do
7070
Agent.get agent_pid, fn(data) ->
7171
conn_map = data[conn_id] || %{}
7272
if is_list(keys) do
73-
Enum.map keys, &Dict.get(conn_map, &1)
73+
Enum.map keys, &Map.get(conn_map, &1)
7474
else
75-
Dict.get(conn_map, keys)
75+
Map.get(conn_map, keys)
7676
end
7777
end
7878
end
@@ -96,7 +96,7 @@ defmodule NSQ.ConnInfo do
9696
"""
9797
def update(agent_pid, conn_id, func) when is_pid(agent_pid) and is_function(func) do
9898
Agent.update agent_pid, fn(data) ->
99-
Dict.put(data, conn_id, func.(data[conn_id] || %{}))
99+
Map.put(data, conn_id, func.(data[conn_id] || %{}))
100100
end
101101
end
102102

@@ -107,8 +107,8 @@ defmodule NSQ.ConnInfo do
107107
"""
108108
def update(agent_pid, conn_id, map) when is_pid(agent_pid) and is_map(map) do
109109
Agent.update agent_pid, fn(data) ->
110-
new_conn_data = Dict.merge(data[conn_id] || %{}, map)
111-
Dict.put(data, conn_id, new_conn_data)
110+
new_conn_data = Map.merge(data[conn_id] || %{}, map)
111+
Map.put(data, conn_id, new_conn_data)
112112
end
113113
end
114114

@@ -130,7 +130,7 @@ defmodule NSQ.ConnInfo do
130130
connection is terminated.
131131
"""
132132
def delete(agent_pid, conn_id) when is_pid(agent_pid) do
133-
Agent.update(agent_pid, fn(data) -> Dict.delete(data, conn_id) end)
133+
Agent.update(agent_pid, fn(data) -> Map.delete(data, conn_id) end)
134134
end
135135

136136

@@ -147,7 +147,7 @@ defmodule NSQ.ConnInfo do
147147
rdy_count: 0,
148148
last_rdy: 0,
149149
messages_in_flight: 0,
150-
last_msg_timestamp: now,
150+
last_msg_timestamp: now(),
151151
retry_rdy_pid: nil,
152152
finished_count: 0,
153153
requeued_count: 0,

lib/nsq/connection.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ defmodule NSQ.Connection do
199199
Logger.error "#{inspect conn}: Timed out waiting for messages to finish. Exiting anyway."
200200
end
201201

202-
Process.exit(self, :normal)
202+
Process.exit(self(), :normal)
203203
end
204204

205205
@doc """

lib/nsq/connection/buffer.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ defmodule NSQ.Connection.Buffer do
4040
state = %{state | compression: :deflate}
4141
case state.type do
4242
:reader ->
43-
%{state | zin: open_zin!} |> convert_plaintext_buffer(:deflate)
43+
%{state | zin: open_zin!()} |> convert_plaintext_buffer(:deflate)
4444
:writer ->
4545
%{state | zout: open_zout!(level)}
4646
end

lib/nsq/connection/initializer.ex

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,21 @@ defmodule NSQ.Connection.Initializer do
3333
{:ok, %{state | connected: true}}
3434
{:error, reason} ->
3535
if length(state.config.nsqlookupds) > 0 do
36-
Logger.warn "(#{inspect self}) connect failed; #{reason}; discovery loop should respawn"
36+
Logger.warn "(#{inspect self()}) connect failed; #{reason}; discovery loop should respawn"
3737
{{:error, reason}, %{state | connect_attempts: state.connect_attempts + 1}}
3838
else
3939
if state.config.max_reconnect_attempts > 0 do
40-
Logger.warn "(#{inspect self}) connect failed; #{reason}; discovery loop should respawn"
40+
Logger.warn "(#{inspect self()}) connect failed; #{reason}; discovery loop should respawn"
4141
{{:error, reason}, %{state | connect_attempts: state.connect_attempts + 1}}
4242
else
43-
Logger.error "(#{inspect self}) connect failed; #{reason}; reconnect turned off; terminating connection"
44-
Process.exit(self, :connect_failed)
43+
Logger.error "(#{inspect self()}) connect failed; #{reason}; reconnect turned off; terminating connection"
44+
Process.exit(self(), :connect_failed)
4545
end
4646
end
4747
end
4848
else
49-
Logger.error "#{inspect self}: Failed to connect; terminating connection"
50-
Process.exit(self, :connect_failed)
49+
Logger.error "#{inspect self()}: Failed to connect; terminating connection"
50+
Process.exit(self(), :connect_failed)
5151
end
5252
end
5353

@@ -77,14 +77,14 @@ defmodule NSQ.Connection.Initializer do
7777

7878
@spec send_magic_v2(C.state) :: :ok
7979
defp send_magic_v2(conn_state) do
80-
Logger.debug("(#{inspect self}) sending magic v2...")
80+
Logger.debug("(#{inspect self()}) sending magic v2...")
8181
conn_state |> Buffer.send!(encode(:magic_v2))
8282
end
8383

8484

8585
@spec identify(C.state) :: {:ok, binary}
8686
defp identify(conn_state) do
87-
Logger.debug("(#{inspect self}) identifying...")
87+
Logger.debug("(#{inspect self()}) identifying...")
8888
identify_obj = encode({:identify, identify_props(conn_state)})
8989
conn_state |> Buffer.send!(identify_obj)
9090
{:response, json} = recv_nsq_response(conn_state)
@@ -186,10 +186,10 @@ defmodule NSQ.Connection.Initializer do
186186

187187
@spec subscribe(C.state) :: {:ok, binary}
188188
defp subscribe(%{topic: topic, channel: channel} = conn_state) do
189-
Logger.debug "(#{inspect self}) subscribe to #{topic} #{channel}"
189+
Logger.debug "(#{inspect self()}) subscribe to #{topic} #{channel}"
190190
conn_state |> Buffer.send!(encode({:sub, topic, channel}))
191191

192-
Logger.debug "(#{inspect self}) wait for subscription acknowledgment"
192+
Logger.debug "(#{inspect self()}) wait for subscription acknowledgment"
193193
conn_state |> wait_for_ok!
194194
end
195195

@@ -203,7 +203,7 @@ defmodule NSQ.Connection.Initializer do
203203

204204

205205
defp wait_for_ok!(state) do
206-
expected = ok_msg
206+
expected = ok_msg()
207207
^expected = state |> Buffer.recv!(byte_size(expected))
208208
end
209209

@@ -233,9 +233,9 @@ defmodule NSQ.Connection.Initializer do
233233

234234
@spec start_receiving_messages(C.state) :: {:ok, C.state}
235235
defp start_receiving_messages(state) do
236-
reader_pid = spawn_link(MessageHandling, :recv_nsq_messages, [state, self])
236+
reader_pid = spawn_link(MessageHandling, :recv_nsq_messages, [state, self()])
237237
state = %{state | reader_pid: reader_pid}
238-
GenServer.cast(self, :flush_cmd_queue)
238+
GenServer.cast(self(), :flush_cmd_queue)
239239
{:ok, state}
240240
end
241241
defp start_receiving_messages!(state) do

lib/nsq/connection/message_handling.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ defmodule NSQ.Connection.MessageHandling do
106106
message = NSQ.Message.from_data(data)
107107
state = received_message(state)
108108
message = %NSQ.Message{message |
109-
connection: self,
109+
connection: self(),
110110
consumer: state.parent,
111111
reader: state.reader,
112112
writer: state.writer,
@@ -127,7 +127,7 @@ defmodule NSQ.Connection.MessageHandling do
127127
%{info |
128128
rdy_count: info.rdy_count - 1,
129129
messages_in_flight: info.messages_in_flight + 1,
130-
last_msg_timestamp: now
130+
last_msg_timestamp: now()
131131
}
132132
end
133133
state

lib/nsq/consumer.ex

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ defmodule NSQ.Consumer do
176176

177177
cons_state = %{cons_state | max_in_flight: cons_state.config.max_in_flight}
178178

179-
{:ok, _cons_state} = Connections.discover_nsqds_and_connect(self, cons_state)
179+
{:ok, _cons_state} = Connections.discover_nsqds_and_connect(self(), cons_state)
180180
end
181181

182182

@@ -187,7 +187,7 @@ defmodule NSQ.Consumer do
187187
@spec handle_call(:redistribute_rdy, {reference, pid}, cons_state) ::
188188
{:reply, :ok, cons_state}
189189
def handle_call(:redistribute_rdy, _from, cons_state) do
190-
{:reply, :ok, RDY.redistribute!(self, cons_state)}
190+
{:reply, :ok, RDY.redistribute!(self(), cons_state)}
191191
end
192192

193193

@@ -218,14 +218,14 @@ defmodule NSQ.Consumer do
218218
@spec handle_call({:start_stop_continue_backoff, atom}, {reference, pid}, cons_state) ::
219219
{:reply, :ok, cons_state}
220220
def handle_call({:start_stop_continue_backoff, backoff_flag}, _from, cons_state) do
221-
{:reply, :ok, Backoff.start_stop_continue!(self, backoff_flag, cons_state)}
221+
{:reply, :ok, Backoff.start_stop_continue!(self(), backoff_flag, cons_state)}
222222
end
223223

224224

225225
@spec handle_call({:update_rdy, connection, integer}, {reference, pid}, cons_state) ::
226226
{:reply, :ok, cons_state}
227227
def handle_call({:update_rdy, conn, count}, _from, cons_state) do
228-
{:reply, :ok, RDY.update!(self, conn, count, cons_state)}
228+
{:reply, :ok, RDY.update!(self(), conn, count, cons_state)}
229229
end
230230

231231

@@ -290,7 +290,7 @@ defmodule NSQ.Consumer do
290290
"""
291291
@spec handle_cast(:resume, cons_state) :: {:noreply, cons_state}
292292
def handle_cast(:resume, state) do
293-
{:noreply, Backoff.resume!(self, state)}
293+
{:noreply, Backoff.resume!(self(), state)}
294294
end
295295

296296

@@ -301,8 +301,8 @@ defmodule NSQ.Consumer do
301301
@spec handle_cast({:maybe_update_rdy, host_with_port}, cons_state) ::
302302
{:noreply, cons_state}
303303
def handle_cast({:maybe_update_rdy, {_host, _port} = nsqd}, cons_state) do
304-
conn = conn_from_nsqd(self, nsqd, cons_state)
305-
{:noreply, RDY.maybe_update!(self, conn, cons_state)}
304+
conn = conn_from_nsqd(self(), nsqd, cons_state)
305+
{:noreply, RDY.maybe_update!(self(), conn, cons_state)}
306306
end
307307

308308

lib/nsq/consumer/connections.ex

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ defmodule NSQ.Consumer.Connections do
2222
lookupd_poll_interval: poll_interval,
2323
lookupd_poll_jitter: poll_jitter
2424
} = cons_state.config
25-
delay = poll_interval + round(poll_interval * poll_jitter * :random.uniform)
25+
delay = poll_interval + round(poll_interval * poll_jitter * :rand.uniform)
2626
:timer.sleep(delay)
2727

2828
GenServer.call(cons, :discover_nsqds)
@@ -31,7 +31,7 @@ defmodule NSQ.Consumer.Connections do
3131

3232

3333
def close(cons_state) do
34-
Logger.info "Closing connections for consumer #{inspect self}"
34+
Logger.info "Closing connections for consumer #{inspect self()}"
3535
connections = get(cons_state)
3636
Enum.map connections, fn({_, conn_pid}) ->
3737
Task.start_link(NSQ.Connection, :close, [conn_pid])
@@ -48,7 +48,7 @@ defmodule NSQ.Consumer.Connections do
4848
def refresh(cons_state) do
4949
{:ok, cons_state} = delete_dead(cons_state)
5050
{:ok, cons_state} = reconnect_failed(cons_state)
51-
{:ok, cons_state} = discover_nsqds_and_connect(self, cons_state)
51+
{:ok, cons_state} = discover_nsqds_and_connect(self(), cons_state)
5252
{:ok, cons_state}
5353
end
5454

@@ -67,12 +67,12 @@ defmodule NSQ.Consumer.Connections do
6767
def discover_nsqds_and_connect(cons, cons_state) do
6868
nsqds = cond do
6969
length(cons_state.config.nsqlookupds) > 0 ->
70-
Logger.debug "(#{inspect self}) Discovering nsqds via nsqlookupds #{inspect cons_state.config.nsqlookupds}"
70+
Logger.debug "(#{inspect self()}) Discovering nsqds via nsqlookupds #{inspect cons_state.config.nsqlookupds}"
7171
cons_state.config.nsqlookupds
7272
|> NSQ.Lookupd.nsqds_with_topic(cons_state.topic)
7373

7474
length(cons_state.config.nsqds) > 0 ->
75-
Logger.debug "(#{inspect self}) Using configured nsqds #{inspect cons_state.config.nsqds}"
75+
Logger.debug "(#{inspect self()}) Using configured nsqds #{inspect cons_state.config.nsqds}"
7676
cons_state.config.nsqds
7777

7878
true ->
@@ -196,7 +196,7 @@ defmodule NSQ.Consumer.Connections do
196196
Not for external use.
197197
"""
198198
@spec cleanup_connection(pid, C.host_with_port, C.state) :: {:ok, C.state}
199-
def cleanup_connection(cons, conn_id, cons_state) do
199+
def cleanup_connection(_cons, conn_id, cons_state) do
200200
# If a connection is terminated normally or non-normally, it will still be
201201
# listed in the supervision tree. Let's remove it when we clean up.
202202
Supervisor.delete_child(cons_state.conn_sup_pid, conn_id)
@@ -284,7 +284,7 @@ defmodule NSQ.Consumer.Connections do
284284
if is_integer(active) do
285285
active
286286
else
287-
Logger.warn "(#{inspect self}) non-integer #{inspect active} returned counting connections, returning 0 instead"
287+
Logger.warn "(#{inspect self()}) non-integer #{inspect active} returned counting connections, returning 0 instead"
288288
0
289289
end
290290
end
@@ -322,7 +322,7 @@ defmodule NSQ.Consumer.Connections do
322322
[last_msg_t, rdy_count] = ConnInfo.fetch(
323323
cons_state, conn_id, [:last_msg_timestamp, :rdy_count]
324324
)
325-
sec_since_last_msg = now - last_msg_t
325+
sec_since_last_msg = now() - last_msg_t
326326
ms_since_last_msg = sec_since_last_msg * 1000
327327

328328
Logger.debug(

lib/nsq/message.ex

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ defmodule NSQ.Message do
3737

3838
def init(message) do
3939
# Process the message asynchronously after init.
40-
GenServer.cast(self, :process)
40+
GenServer.cast(self(), :process)
4141
{:ok, message}
4242
end
4343

@@ -70,7 +70,7 @@ defmodule NSQ.Message do
7070
def process(message) do
7171
# Kick off processing in a separate process, so we can kill it if it takes
7272
# too long.
73-
message = %{message | parent: self}
73+
message = %{message | parent: self()}
7474
{:ok, pid} = Task.start_link fn ->
7575
process_without_timeout(message)
7676
end
@@ -85,7 +85,7 @@ defmodule NSQ.Message do
8585
send(message.connection, result)
8686

8787
# Nothing more for this process to do.
88-
Process.exit(self, :normal)
88+
Process.exit(self(), :normal)
8989
end
9090

9191

@@ -253,7 +253,7 @@ defmodule NSQ.Message do
253253

254254
defp calculate_delay(attempts, max_requeue_delay) do
255255
exponential_backoff = :math.pow(2, attempts) * 1000
256-
jitter = round(0.3 * :random.uniform * exponential_backoff)
256+
jitter = round(0.3 * :rand.uniform * exponential_backoff)
257257
min(
258258
exponential_backoff + jitter,
259259
max_requeue_delay

lib/nsq/producer.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ defmodule NSQ.Producer do
102102
end
103103
pro_state = %{pro_state | event_manager_pid: manager}
104104

105-
{:ok, _pro_state} = connect_to_nsqds(pro_state.config.nsqds, self, pro_state)
105+
{:ok, _pro_state} = connect_to_nsqds(pro_state.config.nsqds, self(), pro_state)
106106
end
107107

108108

0 commit comments

Comments
 (0)