meta changes

e27d884 · Gabriel Morell · 2026-08-17 21:48

5 files +29 -3

Files changed

modified config/runtime.exs
+8 −0
@@ -16,6 +16,14 @@ import Config
16 16 #
17 17 # Alternatively, you can use `mix phx.gen.release` to generate a `bin/server`
18 18 # script that automatically sets the env var above.
19 +# where the dets metadata table is kept — device names/places/order, and the
20 +# persisted machines and links. in the container this wants to be the mounted
21 +# volume, everything else keeps it next to the project.
22 +config :lambent_ex,
23 + :meta_dir,
24 + System.get_env("LEX_META_DIR") ||
25 + if(config_env() == :prod, do: "/opt/app/meta", else: ".")
26 +
19 27 if System.get_env("PHX_SERVER") do
20 28 config :lambent_ex, LambentExWeb.Endpoint,
21 29 server: true,
modified lib/lambent_ex/meta.ex
+21 −3
@@ -6,9 +6,15 @@ defmodule LambentEx.Meta do
6 6 @pubsub_svc "svc_pub"
7 7
8 8 def init(arg) do
9 − # File.cd("meta")
10 − {:ok, table} = :dets.open_file(@table, type: :set)
11 − # File.cd("..")
9 + {:ok, table} =
10 + :dets.open_file(@table,
11 + type: :set,
12 + file: dets_file(),
13 + # default is three minutes, which is a lot to lose to a hard restart.
14 + # the flush loops below dirty the table every 5s, so this is what
15 + # actually sets how often the file is written.
16 + auto_save: :timer.seconds(30)
17 + )
12 18
13 19 Phoenix.PubSub.subscribe(@pubsub_name, "machines_idx")
14 20 Phoenix.PubSub.subscribe(@pubsub_name, "links_idx")
@@ -26,6 +32,18 @@ defmodule LambentEx.Meta do
26 32 GenServer.start_link(__MODULE__, arg, name: __MODULE__)
27 33 end
28 34
35 + @doc """
36 + Where the dets table lives. Left to itself dets names the file after the
37 + table and drops it in the cwd, which in a container is a layer that does not
38 + survive the next start, so point it at whatever is mounted instead.
39 + """
40 + def dets_file do
41 + dir = Application.get_env(:lambent_ex, :meta_dir) || System.get_env("LEX_META_DIR") || "."
42 + File.mkdir_p!(dir)
43 +
44 + dir |> Path.join(Kernel.to_string(@table)) |> String.to_charlist()
45 + end
46 +
29 47 # devices
30 48 def get_name(mac) do
31 49 case :dets.lookup(@table, "name-#{mac}") do

Parents: 44aeeea