Updated config to expose the current env globally; updated startup tasks to not run in test env
This commit is contained in:
parent
15bb8d4190
commit
c92a07ebc2
6 changed files with 31 additions and 6 deletions
|
|
@ -10,6 +10,7 @@ import Config
|
|||
config :pinchflat,
|
||||
ecto_repos: [Pinchflat.Repo],
|
||||
generators: [timestamp_type: :utc_datetime],
|
||||
env: config_env(),
|
||||
# Specifying backend data here makes mocking and local testing SUPER easy
|
||||
yt_dlp_executable: System.find_executable("yt-dlp"),
|
||||
apprise_executable: System.find_executable("apprise"),
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
defmodule Pinchflat.Boot.PostJobStartupTasks do
|
||||
@moduledoc """
|
||||
This module is responsible for running startup tasks on app boot
|
||||
AFTER the job runner has initiallized.
|
||||
AFTER the job runner has initialized.
|
||||
|
||||
It's a GenServer because that plays REALLY nicely with the existing
|
||||
Phoenix supervision tree.
|
||||
|
|
@ -12,7 +12,7 @@ defmodule Pinchflat.Boot.PostJobStartupTasks do
|
|||
import Ecto.Query, warn: false
|
||||
|
||||
def start_link(opts \\ []) do
|
||||
GenServer.start_link(__MODULE__, %{}, opts)
|
||||
GenServer.start_link(__MODULE__, %{env: Application.get_env(:pinchflat, :env)}, opts)
|
||||
end
|
||||
|
||||
@doc """
|
||||
|
|
@ -25,6 +25,13 @@ defmodule Pinchflat.Boot.PostJobStartupTasks do
|
|||
Should be fast - anything with the potential to be slow should be kicked off as a job instead.
|
||||
"""
|
||||
@impl true
|
||||
def init(%{env: :test} = state) do
|
||||
# Do nothing _as part of the app bootup process_.
|
||||
# Since bootup calls `start_link` and that's where the `env` state is injected,
|
||||
# you can still call `.init()` manually to run these tasks for testing purposes
|
||||
{:ok, state}
|
||||
end
|
||||
|
||||
def init(state) do
|
||||
# Nothing at the moment!
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ defmodule Pinchflat.Boot.PreJobStartupTasks do
|
|||
alias Pinchflat.Lifecycle.UserScripts.CommandRunner, as: UserScriptRunner
|
||||
|
||||
def start_link(opts \\ []) do
|
||||
GenServer.start_link(__MODULE__, %{}, opts)
|
||||
GenServer.start_link(__MODULE__, %{env: Application.get_env(:pinchflat, :env)}, opts)
|
||||
end
|
||||
|
||||
@doc """
|
||||
|
|
@ -32,6 +32,13 @@ defmodule Pinchflat.Boot.PreJobStartupTasks do
|
|||
Should be fast - anything with the potential to be slow should be kicked off as a job instead.
|
||||
"""
|
||||
@impl true
|
||||
def init(%{env: :test} = state) do
|
||||
# Do nothing _as part of the app bootup process_.
|
||||
# Since bootup calls `start_link` and that's where the `env` state is injected,
|
||||
# you can still call `.init()` manually to run these tasks for testing purposes
|
||||
{:ok, state}
|
||||
end
|
||||
|
||||
def init(state) do
|
||||
ensure_tmpfile_directory()
|
||||
reset_executing_jobs()
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ defmodule Pinchflat.Profiles.MediaProfileDeletionWorker do
|
|||
Starts the profile deletion worker. Does not attach it to a task like `kickoff_with_task/2`
|
||||
since deletion also cancels all tasks for the profile
|
||||
|
||||
Returns {:ok, %Task{}} | {:error, %Ecto.Changeset{}}
|
||||
Returns {:ok, %Oban.Job{}} | {:error, %Ecto.Changeset{}}
|
||||
"""
|
||||
def kickoff(profile, job_args \\ %{}, job_opts \\ []) do
|
||||
%{id: profile.id}
|
||||
|
|
|
|||
|
|
@ -7,12 +7,22 @@ defmodule Pinchflat.YtDlp.UpdateWorker do
|
|||
|
||||
require Logger
|
||||
|
||||
alias __MODULE__
|
||||
alias Pinchflat.Settings
|
||||
|
||||
@doc """
|
||||
Starts the yt-dlp update worker. Does not attach it to a task like `kickoff_with_task/2`
|
||||
|
||||
Returns {:ok, %Oban.Job{}} | {:error, %Ecto.Changeset{}}
|
||||
"""
|
||||
def kickoff do
|
||||
Oban.insert(UpdateWorker.new(%{}))
|
||||
end
|
||||
|
||||
@doc """
|
||||
Updates yt-dlp and saves the version to the settings.
|
||||
|
||||
This worker is scheduled to run via the Oban Cron plugin.
|
||||
This worker is scheduled to run via the Oban Cron plugin as well as on app boot.
|
||||
|
||||
Returns :ok
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ defmodule PinchflatWeb.Endpoint do
|
|||
plug Plug.Static,
|
||||
at: "/",
|
||||
from: :pinchflat,
|
||||
gzip: Mix.env() == :prod,
|
||||
gzip: Application.compile_env(:pinchflat, :env) == :prod,
|
||||
only: PinchflatWeb.static_paths()
|
||||
|
||||
# Code reloading can be explicitly enabled under the
|
||||
|
|
|
|||
Loading…
Reference in a new issue