Skip to content

Commit

Permalink
Merge pull request #6 from semlabs/master
Browse files Browse the repository at this point in the history
Fix reconnection on failure and add tuple handling
  • Loading branch information
kyleaa authored Jan 15, 2018
2 parents c1d3ee7 + 10ece26 commit 2e0146d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions lib/libcluster_ec2.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ defmodule ClusterEC2 do
@moduledoc File.read!("#{__DIR__}/../README.md")

plug Tesla.Middleware.BaseUrl, "http://169.254.169.254/latest/meta-data"
plug Tesla.Middleware.Tuples

@doc """
Queries the local EC2 instance metadata API to determine the instance ID of the current instance.
"""
@spec local_instance_id() :: binary()
def local_instance_id do
case get("/instance-id/") do
%{status: 200, body: body} -> body
{:ok, %{status: 200, body: body}} -> body
_ -> ""
end
end
Expand All @@ -23,7 +24,7 @@ defmodule ClusterEC2 do
@spec instance_region() :: binary()
def instance_region do
case get("/placement/availability-zone/") do
%{status: 200, body: body} -> String.slice(body, 0..-2)
{:ok, %{status: 200, body: body}} -> String.slice(body, 0..-2)
_ -> ""
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/strategy/tags.ex
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ defmodule ClusterEC2.Strategy.Tags do
Process.send_after(self(), :load, Keyword.get(state.config, :polling_interval, @default_polling_interval))
{:noreply, %{state | :meta => new_nodelist}}
_ ->
Process.send_after(self(), :load, Keyword.get(state.config, :polling_interval, @default_polling_interval))
{:noreply, state}
end
end
Expand Down
4 changes: 2 additions & 2 deletions test/libcluster_ec2_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ defmodule ClusterEC2Test do
:ok
end

test "test return local_instance_id" do
test "return local_instance_id" do
assert "i-0fdde7ca9faef9751" == ClusterEC2.local_instance_id()
end

test "test return instance_region" do
test "return instance_region" do
assert "eu-central-1" == ClusterEC2.instance_region()
end
end

0 comments on commit 2e0146d

Please sign in to comment.