Skip to content
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
17 changes: 14 additions & 3 deletions lib/hexdocs/cdn/fastly.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,29 @@ defmodule Hexdocs.CDN.Fastly do
service_id = Application.get_env(:hexdocs, service)
sleep_time = div(Application.get_env(:hexdocs, :fastly_purge_wait, @fastly_purge_wait), 2)

{:ok, 200, _, _} = post("service/#{service_id}/purge", body)
purge!(service, service_id, body)

Task.Supervisor.start_child(Hexdocs.Tasks, fn ->
Process.sleep(sleep_time)
{:ok, 200, _, _} = post("service/#{service_id}/purge", body)
purge!(service, service_id, body)
Process.sleep(sleep_time)
{:ok, 200, _, _} = post("service/#{service_id}/purge", body)
purge!(service, service_id, body)
end)

:ok
end

defp purge!(service, service_id, body) do
case post("service/#{service_id}/purge", body) do
{:ok, 200, _headers, _body} ->
:ok

{:ok, status, _headers, body} ->
raise "failed to purge #{service} (service id: #{service_id}), " <>
"status: #{status}, body: #{inspect(body)}"
end
end

defp auth() do
Application.get_env(:hexdocs, :fastly_key)
end
Expand Down
15 changes: 11 additions & 4 deletions lib/hexdocs/queue.ex
Original file line number Diff line number Diff line change
Expand Up @@ -400,10 +400,17 @@ defmodule Hexdocs.Queue do
task = Task.Supervisor.async(Hexdocs.Tasks, fun)

case Task.yield(task, :timer.seconds(270)) || Task.shutdown(task) do
{:ok, result} -> result
{:exit, {exception, stacktrace}} -> reraise(exception, stacktrace)
{:exit, reason} -> exit(reason)
nil -> raise "task timeout"
{:ok, result} ->
result

{:exit, {exception, stacktrace}} when is_exception(exception) ->
reraise(exception, stacktrace)

{:exit, reason} ->
exit(reason)

nil ->
raise "task timeout"
end
end

Expand Down