|
|
@@ -3,6 +3,7 @@ defmodule CvGen.Watchdog do
|
|
|
require Logger
|
|
|
|
|
|
@name __MODULE__
|
|
|
+ @paths CvGen.paths()
|
|
|
|
|
|
def start_link(_), do: GenServer.start(__MODULE__, [], name: @name)
|
|
|
|
|
|
@@ -14,8 +15,8 @@ defmodule CvGen.Watchdog do
|
|
|
@impl true
|
|
|
def handle_info(:timer_expired, state) do
|
|
|
state =
|
|
|
- with tpl_hash <- hash("lib/templates/cv.html.heex"),
|
|
|
- json_hash <- hash("lib/templates/cv.json") do
|
|
|
+ with tpl_hash <- hash(@paths.template),
|
|
|
+ json_hash <- hash(@paths.data) do
|
|
|
if tpl_hash != state.tpl_hash or json_hash != state.json_hash do
|
|
|
Logger.info("Content has changed, reloading")
|
|
|
CvGen.generate()
|
|
|
@@ -37,8 +38,7 @@ defmodule CvGen.Watchdog do
|
|
|
def handle_call(:reload, _, _) do
|
|
|
CvGen.generate()
|
|
|
|
|
|
- {:reply, :ok,
|
|
|
- %{tpl_hash: hash("lib/templates/cv.html.eex"), json_hash: hash("lib/templates/cv.json")},
|
|
|
+ {:reply, :ok, %{tpl_hash: hash(@paths.template), json_hash: hash(@paths.data)},
|
|
|
{:continue, :trigger_timer}}
|
|
|
end
|
|
|
|