Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix reconnection on failure and add tuple handling #6

Merged
merged 2 commits into from
Jan 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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