-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
90 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
defmodule Hex.Application do | ||
@moduledoc false | ||
|
||
use Application | ||
|
||
def start(_, _) do | ||
dev_setup() | ||
|
||
Mix.SCM.append(Hex.SCM) | ||
Mix.RemoteConverger.register(Hex.RemoteConverger) | ||
|
||
Hex.Version.start() | ||
start_httpc() | ||
|
||
opts = [strategy: :one_for_one, name: Hex.Supervisor] | ||
Supervisor.start_link(children(), opts) | ||
end | ||
|
||
if Mix.env() in [:dev, :test] do | ||
defp dev_setup do | ||
:erlang.system_flag(:backtrace_depth, 20) | ||
end | ||
else | ||
defp dev_setup, do: :ok | ||
end | ||
|
||
defp start_httpc() do | ||
:inets.start(:httpc, profile: :hex) | ||
|
||
opts = [ | ||
max_sessions: 8, | ||
max_keep_alive_length: 4, | ||
keep_alive_timeout: 120_000 | ||
] | ||
|
||
:httpc.set_options(opts, :hex) | ||
end | ||
|
||
defmacrop worker(module) do | ||
if Version.compare(System.version(), "1.5.0") == :lt do | ||
import Supervisor.Spec | ||
quote do: worker(unquote(module), [[]]) | ||
else | ||
quote do: unquote(module) | ||
end | ||
end | ||
|
||
defmacrop worker(module, args) do | ||
if Version.compare(System.version(), "1.5.0") == :lt do | ||
import Supervisor.Spec | ||
quote do: worker(unquote(module), [unquote(args)]) | ||
else | ||
quote do: {unquote(module), unquote(args)} | ||
end | ||
end | ||
|
||
if Mix.env() == :test do | ||
defp children do | ||
[ | ||
worker(Hex.State), | ||
worker(Hex.Server), | ||
worker(Hex.Parallel, [:hex_fetcher]) | ||
] | ||
end | ||
else | ||
defp children do | ||
[ | ||
worker(Hex.State), | ||
worker(Hex.Server), | ||
worker(Hex.Parallel, [:hex_fetcher]), | ||
worker(Hex.Registry.Server), | ||
worker(Hex.UpdateChecker) | ||
] | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters