Skip to content

Commit

Permalink
Limit start timeout to 10_000ms
Browse files Browse the repository at this point in the history
  • Loading branch information
Dylan Kendal committed Mar 5, 2017
1 parent 19ac51e commit bbbfada
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
3 changes: 3 additions & 0 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ config :battle_snake, BattleSnake.Endpoint,
pubsub: [name: BattleSnake.PubSub,
adapter: Phoenix.PubSub.PG2]


config :battle_snake, start_timeout: 10_000

# Configures Elixir's Logger
config :logger, :console,
format: "$time $metadata[$level] $message\n",
Expand Down
4 changes: 3 additions & 1 deletion lib/battle_snake/api.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ defmodule BattleSnake.Api do

require Logger

@start_timeout Application.get_env(:battle_snake, :start_timeout)

@callback load(%SnakeForm{}, %GameForm{}) :: Response.t
@callback move(%Snake{}, %World{}) :: Response.t
@callback request_move(%Snake{}, %World{}) :: HTTPoison.Response.t
Expand All @@ -27,7 +29,7 @@ defmodule BattleSnake.Api do
data = Poison.encode!(data)

response = request_url
|> request.(data, ["content-type": "application/json"], [])
|> request.(data, ["content-type": "application/json"], [recv_timeout: @start_timeout])
|> Response.new(as: %{})

response = put_in(response.url, url)
Expand Down
2 changes: 1 addition & 1 deletion lib/battle_snake/game_form/reset.ex
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ defmodule BattleSnake.GameForm.Reset do

update_in(game_form.world.snakes, fn _ ->
game_form.snakes
|> Task.async_stream(task)
|> Task.async_stream(task, [timeout: :infinity])
|> Enum.map(fn {:ok, snake} -> snake end)
end)
end
Expand Down

0 comments on commit bbbfada

Please sign in to comment.