Skip to content

Commit

Permalink
Log and rescue only static warmup, closes #5389
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Mar 30, 2023
1 parent 319ff88 commit f8c0ad2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 25 deletions.
37 changes: 17 additions & 20 deletions lib/phoenix/endpoint/supervisor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -309,10 +309,14 @@ defmodule Phoenix.Endpoint.Supervisor do
"""
def warmup(endpoint) do
warmup_persistent(endpoint)
warmup_static(endpoint, cache_static_manifest(endpoint))
true
rescue
_ -> false

try do
if manifest = cache_static_manifest(endpoint) do
warmup_static(endpoint, manifest)
end
rescue
e -> Logger.error("Could not warm up static assets: #{Exception.message(e)}")
end
end

defp warmup_persistent(endpoint) do
Expand Down Expand Up @@ -347,14 +351,9 @@ defmodule Phoenix.Endpoint.Supervisor do

{scheme, port} =
cond do
https ->
{"https", https[:port]}

http ->
{"http", http[:port]}

true ->
{"http", 80}
https -> {"https", https[:port] || 443}
http -> {"http", http[:port] || 80}
true -> {"http", 80}
end

scheme = url[:scheme] || scheme
Expand Down Expand Up @@ -382,8 +381,7 @@ defmodule Phoenix.Endpoint.Supervisor do
end

defp warmup_static(_endpoint, _manifest) do
raise ArgumentError,
"expected warmup_static/2 to include 'latest' and 'digests' keys in manifest"
raise ArgumentError, "expected cache manifest to include 'latest' and 'digests' keys"
end

defp static_cache(digests, value, true) do
Expand Down Expand Up @@ -411,14 +409,13 @@ defmodule Phoenix.Endpoint.Supervisor do
if File.exists?(outer) do
outer |> File.read!() |> Phoenix.json_library().decode!()
else
Logger.error(
"Could not find static manifest at #{inspect(outer)}. " <>
"Run \"mix phx.digest\" after building your static files " <>
"or remove the \"cache_static_manifest\" configuration from your config files."
)
raise ArgumentError,
"could not find static manifest at #{inspect(outer)}. " <>
"Run \"mix phx.digest\" after building your static files " <>
"or remove the \"cache_static_manifest\" configuration from your config files."
end
else
%{}
nil
end
end

Expand Down
11 changes: 6 additions & 5 deletions test/phoenix/endpoint/supervisor_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,38 @@ defmodule Phoenix.Endpoint.SupervisorTest do
def config(:https), do: [port: 443]
def config(:http), do: false
def config(:url), do: [host: "example.com"]
def config(:static_url), do: nil
def config(_), do: nil
end

defmodule HTTPEndpoint do
def config(:otp_app), do: :phoenix
def config(:https), do: false
def config(:http), do: [port: 80]
def config(:url), do: [host: "example.com"]
def config(:static_url), do: nil
def config(_), do: nil
end

defmodule HTTPEnvVarEndpoint do
def config(:otp_app), do: :phoenix
def config(:https), do: false
def config(:http), do: [port: {:system, "PHOENIX_PORT"}]
def config(:url), do: [host: {:system, "PHOENIX_HOST"}]
def config(:static_url), do: nil
def config(_), do: nil
end

defmodule URLEndpoint do
def config(:https), do: false
def config(:http), do: false
def config(:url), do: [host: "example.com", port: 678, scheme: "random"]
def config(:static_url), do: nil
def config(_), do: nil
end

defmodule StaticURLEndpoint do
def config(:https), do: false
def config(:http), do: false
def config(:http), do: []
def config(:url), do: []
def config(:static_url), do: [host: "static.example.com"]
def config(_), do: nil
end

defmodule ServerEndpoint do
Expand Down

0 comments on commit f8c0ad2

Please sign in to comment.