Ensured tempfile directory on app boot
This commit is contained in:
parent
f479bc88e1
commit
d5ebb2a22a
2 changed files with 24 additions and 0 deletions
|
|
@ -31,6 +31,7 @@ defmodule Pinchflat.Boot.PreJobStartupTasks do
|
|||
"""
|
||||
@impl true
|
||||
def init(state) do
|
||||
ensure_tmpfile_directory()
|
||||
reset_executing_jobs()
|
||||
create_blank_yt_dlp_files()
|
||||
create_blank_user_script_file()
|
||||
|
|
@ -39,6 +40,14 @@ defmodule Pinchflat.Boot.PreJobStartupTasks do
|
|||
{:ok, state}
|
||||
end
|
||||
|
||||
defp ensure_tmpfile_directory do
|
||||
tmpfile_dir = Application.get_env(:pinchflat, :tmpfile_directory)
|
||||
|
||||
if !File.exists?(tmpfile_dir) do
|
||||
File.mkdir_p!(tmpfile_dir)
|
||||
end
|
||||
end
|
||||
|
||||
# If a node cannot gracefully shut down, the currently executing jobs get stuck
|
||||
# in the "executing" state. This is a problem because the job runner will not
|
||||
# pick them up again
|
||||
|
|
|
|||
|
|
@ -13,6 +13,19 @@ defmodule Pinchflat.Boot.PreJobStartupTasksTest do
|
|||
:ok
|
||||
end
|
||||
|
||||
describe "ensure_tmpfile_directory" do
|
||||
test "creates the tmpfile directory if it doesn't exist" do
|
||||
tmpfile_dir = Application.get_env(:pinchflat, :tmpfile_directory)
|
||||
File.rm_rf!(tmpfile_dir)
|
||||
|
||||
refute File.exists?(tmpfile_dir)
|
||||
|
||||
PreJobStartupTasks.init(%{})
|
||||
|
||||
assert File.exists?(tmpfile_dir)
|
||||
end
|
||||
end
|
||||
|
||||
describe "reset_executing_jobs" do
|
||||
test "resets executing jobs" do
|
||||
job = job_fixture()
|
||||
|
|
@ -78,6 +91,7 @@ defmodule Pinchflat.Boot.PreJobStartupTasksTest do
|
|||
|
||||
describe "apply_default_settings" do
|
||||
test "sets yt_dlp version" do
|
||||
File.rm_rf!(Application.get_env(:pinchflat, :tmpfile_directory))
|
||||
Settings.set(yt_dlp_version: nil)
|
||||
|
||||
refute Settings.get!(:yt_dlp_version)
|
||||
|
|
@ -88,6 +102,7 @@ defmodule Pinchflat.Boot.PreJobStartupTasksTest do
|
|||
end
|
||||
|
||||
test "sets apprise version" do
|
||||
File.rm_rf!(Application.get_env(:pinchflat, :tmpfile_directory))
|
||||
Settings.set(apprise_version: nil)
|
||||
|
||||
refute Settings.get!(:apprise_version)
|
||||
|
|
|
|||
Loading…
Reference in a new issue