Skip to content

Commit

Permalink
Do not schedule idle shutdown until after code sync
Browse files Browse the repository at this point in the history
  • Loading branch information
chrismccord committed Sep 3, 2024
1 parent b379452 commit 30f0da7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
17 changes: 11 additions & 6 deletions lib/flame/code_sync.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ defmodule FLAME.CodeSync.PackagedStream do
deleted_paths: [],
purge_modules: [],
verbose: false,
compress: false
compress: false,
chunk_size: 64_000
end

defmodule FLAME.CodeSync do
Expand All @@ -32,7 +33,8 @@ defmodule FLAME.CodeSync do
deleted_paths: [],
purge_modules: [],
verbose: false,
compress: false
compress: false,
chunk_size: 64_000

def new(opts \\ []) do
Keyword.validate!(opts, [
Expand All @@ -42,7 +44,8 @@ defmodule FLAME.CodeSync do
:sync_beams,
:start_apps,
:verbose,
:compress
:compress,
:chunk_size
])

copy_paths =
Expand Down Expand Up @@ -76,7 +79,8 @@ defmodule FLAME.CodeSync do
extract_dir: Keyword.get(opts, :extract_dir, {Function, :identity, ["/"]}),
start_apps: Keyword.get(opts, :start_apps, true),
verbose: Keyword.get(opts, :verbose, false),
compress: Keyword.get(opts, :compress, false)
compress: Keyword.get(opts, :compress, false),
chunk_size: Keyword.get(opts, :chunk_size, 64_000)
})
end

Expand Down Expand Up @@ -169,7 +173,7 @@ defmodule FLAME.CodeSync do

:ok = :erl_tar.close(tar)

File.stream!(out_path, [], 64_000)
File.stream!(out_path, [], code.chunk_size)
end

%PackagedStream{
Expand All @@ -183,7 +187,8 @@ defmodule FLAME.CodeSync do
apps_to_start: code.apps_to_start,
stream: out_stream,
verbose: code.verbose,
compress: code.compress
compress: code.compress,
chunk_size: code.chunk_size
}
end

Expand Down
4 changes: 3 additions & 1 deletion lib/flame/pool.ex
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,8 @@ defmodule FLAME.Pool do
:sync_beams,
:start_apps,
:verbose,
:compress
:compress,
:chunk_size
])

GenServer.start_link(__MODULE__, opts, name: Keyword.fetch!(opts, :name))
Expand Down Expand Up @@ -403,6 +404,7 @@ defmodule FLAME.Pool do
if code_sync_opts = opts[:code_sync] do
code_sync = CodeSync.new(Keyword.put(code_sync_opts, :sync_beams, []))
%CodeSync.PackagedStream{} = parent_stream = CodeSync.package_to_stream(code_sync)
IO.inspect(File.stat!(parent_stream.stream.path))
parent_stream
end

Expand Down
8 changes: 5 additions & 3 deletions lib/flame/runner.ex
Original file line number Diff line number Diff line change
Expand Up @@ -306,11 +306,12 @@ defmodule FLAME.Runner do
# ensure app is fully started if parent connects before up
if otp_app, do: {:ok, _} = Application.ensure_all_started(otp_app)

if base_sync_stream, do: CodeSync.extract_packaged_stream(base_sync_stream)
if beams_stream, do: CodeSync.extract_packaged_stream(beams_stream)

:ok =
Terminator.schedule_idle_shutdown(term, idle_after, idle_check, single_use)

if base_sync_stream, do: CodeSync.extract_packaged_stream(base_sync_stream)
if beams_stream, do: CodeSync.extract_packaged_stream(beams_stream)
:ok
end)

Expand Down Expand Up @@ -348,7 +349,8 @@ defmodule FLAME.Runner do
:tmp_dir,
:extract_dir,
:verbose,
:compress
:compress,
:chunk_size
])

{idle_shutdown_after_ms, idle_check} =
Expand Down

0 comments on commit 30f0da7

Please sign in to comment.