Explorar el Código

Add a force_reload function

theenglishway (time) hace 2 años
padre
commit
7b9ea42d7a
Se han modificado 1 ficheros con 14 adiciones y 1 borrados
  1. 14 1
      cv_gen/lib/watchdog.ex

+ 14 - 1
cv_gen/lib/watchdog.ex

@@ -2,7 +2,11 @@ defmodule CvGen.Watchdog do
   use GenServer
   require Logger
 
-  def start_link(_), do: GenServer.start(__MODULE__, [])
+  @name __MODULE__
+
+  def start_link(_), do: GenServer.start(__MODULE__, [], name: @name)
+
+  def force_reload(), do: GenServer.call(@name, :reload, 500)
 
   @impl true
   def init(_), do: {:ok, %{tpl_hash: "", json_hash: ""}, {:continue, :trigger_timer}}
@@ -29,6 +33,15 @@ defmodule CvGen.Watchdog do
     :crypto.hash(:md5, contents) |> Base.encode16()
   end
 
+  @impl true
+  def handle_call(:reload, _, _) do
+    CvGen.generate()
+
+    {:reply, :ok,
+     %{tpl_hash: hash("lib/templates/cv.html.eex"), json_hash: hash("lib/templates/cv.json")},
+     {:continue, :trigger_timer}}
+  end
+
   @impl true
   def handle_continue(:trigger_timer, state) do
     Process.send_after(self(), :timer_expired, 100)