Skip to content

Commit

Permalink
fix(Handler): account the offset for reset time
Browse files Browse the repository at this point in the history
  • Loading branch information
SpaceEEC committed Jun 26, 2018
1 parent 0e450fd commit 3f0ca72
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions lib/rest/handler/handler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -128,17 +128,17 @@ defmodule Crux.Rest.Handler do
handle_call({:queue, request_data}, from, state)

true ->
wait_time =
reset_time =
case state do
%{reset: reset} when not is_nil(reset) ->
%{reset: reset} when is_integer(reset) ->
reset - :os.system_time(:milli_seconds)

_ ->
# 500 for sanity and in the case further messages are queued up
500
end

{:ok, ref} = :timer.send_after(wait_time, :shutdown)
{:ok, ref} = :timer.send_after(reset_time, :shutdown)

{:reply, res, Map.put(state, :timer, ref)}
end
Expand All @@ -158,9 +158,12 @@ defmodule Crux.Rest.Handler do
|> parse_header

state =
if remaining && reset,
do: Map.merge(state, %{remaining: remaining, reset: reset * 1000}),
else: state
if remaining && reset do
reset = reset * 1000 + fetch_offset()
Map.merge(state, %{remaining: remaining, reset: reset})
else
state
end

handle_response(tuple, state, reset)
end
Expand Down

0 comments on commit 3f0ca72

Please sign in to comment.