Skip to content

Commit

Permalink
Fix idle shutdown being schedule before code sync (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrismccord authored Sep 3, 2024
1 parent d0a0fe7 commit d20d9f6
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 11 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 0.4.3 (2024-09-02)

### Bug Fixes
- Fix `:compress` to `:code_sync` raise invalid option error

## 0.4.2 (2024-08-27)

### Enhancements
Expand Down
21 changes: 15 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,11 @@ defmodule FLAME.CodeSync do

:ok = :erl_tar.close(tar)

File.stream!(out_path, [], 64_000)
if code.verbose do
log_verbose("packaged size: #{File.stat!(out_path).size / (1024 * 1024)}mb")
end

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

%PackagedStream{
Expand All @@ -183,7 +191,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
3 changes: 2 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
9 changes: 6 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 @@ -347,7 +348,9 @@ defmodule FLAME.Runner do
:start_apps,
:tmp_dir,
:extract_dir,
:verbose
:verbose,
:compress,
:chunk_size
])

{idle_shutdown_after_ms, idle_check} =
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule FLAME.Runner.MixProject do
def project do
[
app: :flame,
version: "0.4.2",
version: "0.4.3",
elixir: "~> 1.15",
elixirc_paths: elixirc_paths(Mix.env()),
start_permanent: Mix.env() == :prod,
Expand Down

0 comments on commit d20d9f6

Please sign in to comment.