Tell the workers their config changed instead of having them ask

6193c2b · Gabriel Morell · 2026-09-01 18:37

52 files +294 -21
Message
{commit_body(@commit)}

Files changed

modified apps/room_bourse/lib/room_bourse/worker.ex
+5 −1
@@ -36,7 +36,11 @@ defmodule RoomBourse.Worker do
36 36
37 37 def init(opts) do
38 38 Periodic.start_link(
39 − every: :timer.seconds(10),
39 + # A backstop rather than a poll: source config changes are rare, and the
40 + # workers that read them on a tight timer were the load that kept a
41 + # ten-connection pool saturated. Nothing here needs to notice an edit
42 + # within ten seconds.
43 + every: :timer.seconds(60),
40 44 run: fn -> RoomBourse.Worker.refresh_db_cfg(opts[:name]) end,
41 45 initial_delay: 0
42 46 )
modified apps/room_drought/lib/room_drought/worker.ex
+5 −1
@@ -16,7 +16,11 @@ defmodule RoomDrought.Worker do
16 16
17 17 def init(opts) do
18 18 Periodic.start_link(
19 − every: :timer.seconds(10),
19 + # A backstop rather than a poll: source config changes are rare, and the
20 + # workers that read them on a tight timer were the load that kept a
21 + # ten-connection pool saturated. Nothing here needs to notice an edit
22 + # within ten seconds.
23 + every: :timer.seconds(60),
20 24 run: fn -> RoomDrought.Worker.refresh_db_cfg(opts[:name]) end,
21 25 initial_delay: 0
22 26 )
modified apps/room_github/lib/room_github/worker.ex
+5 −1
@@ -16,7 +16,11 @@ defmodule RoomGithub.Worker do
16 16
17 17 def init(opts) do
18 18 Periodic.start_link(
19 − every: :timer.seconds(10),
19 + # A backstop rather than a poll: source config changes are rare, and the
20 + # workers that read them on a tight timer were the load that kept a
21 + # ten-connection pool saturated. Nothing here needs to notice an edit
22 + # within ten seconds.
23 + every: :timer.seconds(60),
20 24 run: fn -> RoomGithub.Worker.refresh_db_cfg(opts[:name]) end,
21 25 initial_delay: 0
22 26 )
modified apps/room_gitlab/lib/room_gitlab/gitlab_worker.ex
+5 −1
@@ -18,7 +18,11 @@ defmodule RoomGitlab.Worker do
18 18
19 19 def init(opts) do
20 20 Periodic.start_link(
21 − every: :timer.seconds(10),
21 + # A backstop rather than a poll: source config changes are rare, and the
22 + # workers that read them on a tight timer were the load that kept a
23 + # ten-connection pool saturated. Nothing here needs to notice an edit
24 + # within ten seconds.
25 + every: :timer.seconds(60),
22 26 run: fn -> RoomGitlab.Worker.refresh_db_cfg(opts[:name]) end,
23 27 initial_delay: 0
24 28 )
modified apps/room_gtfs/lib/room_gtfs/gtfs_worker.ex
+32 −4
@@ -381,8 +381,14 @@ defmodule RoomGtfs.Worker do
381 381
382 382 # etc
383 383 def init(opts) do
384 + Configuration.subscribe(:source, opts[:name])
385 +
384 386 Periodic.start_link(
385 − every: :timer.seconds(4),
387 + # A backstop, not the mechanism: an edit to the source arrives by
388 + # broadcast the moment it is written. This only catches a write that
389 + # never went through Configuration -- a migration, or a hand at a psql
390 + # prompt.
391 + every: :timer.seconds(60),
386 392 run: fn -> RoomGtfs.Worker.refresh_db_cfg(opts[:name]) end,
387 393 initial_delay: 10
388 394 )
@@ -449,6 +455,14 @@ defmodule RoomGtfs.Worker do
449 455 {:noreply, state}
450 456 end
451 457
458 + # Told rather than asked: the same refresh, run when somebody edits the
459 + # source instead of every four seconds in case they did.
460 + def handle_info({:cfg_changed, :source, _id}, state) do
461 + handle_cast(:refresh_db_cfg, state)
462 + end
463 +
464 + def handle_info(_msg, state), do: {:noreply, state}
465 +
452 466 def handle_call({:query_realtime, trips, stop}, _from, state) do
453 467 r =
454 468 try do
@@ -537,8 +551,14 @@ defmodule RoomGtfs.Worker.RT do
537 551 end
538 552
539 553 def init(opts) do
554 + Configuration.subscribe(:source, opts[:name])
555 +
540 556 Periodic.start_link(
541 − every: :timer.seconds(4),
557 + # A backstop, not the mechanism: an edit to the source arrives by
558 + # broadcast the moment it is written. This only catches a write that
559 + # never went through Configuration -- a migration, or a hand at a psql
560 + # prompt.
561 + every: :timer.seconds(60),
542 562 run: fn -> RoomGtfs.Worker.RT.refresh_db_cfg(opts[:name]) end,
543 563 initial_delay: :timer.seconds(10)
544 564 )
@@ -1019,14 +1039,22 @@ defmodule RoomGtfs.Worker.RT do
1019 1039 do_update_realtime(state)
1020 1040 end
1021 1041
1042 + # Told rather than asked: the same refresh, run when somebody edits the
1043 + # source instead of every four seconds in case they did.
1044 + def handle_info({:cfg_changed, :source, _id}, state) do
1045 + handle_cast(:refresh_db_cfg, state)
1046 + end
1047 +
1048 + def handle_info(_msg, state), do: {:noreply, state}
1049 +
1022 1050 # Each kind keeps its own clock. Trip updates go stale in seconds; service
1023 1051 # alerts change a few times a day, and polling them as often as vehicle
1024 1052 # positions buys nothing and costs a request -- which matters where the feed
1025 1053 # is metered, and is simply waste where it is not.
1026 1054 #
1027 1055 # Gated here rather than by rescheduling the Periodic, which cannot be changed
1028 − # once started and would have to be torn down and rebuilt whenever the config
1029 − # is refreshed -- every four seconds, as it happens.
1056 + # once started and would have to be torn down and rebuilt on every config
1057 + # refresh.
1030 1058 defp due?(state, url, period) do
1031 1059 case state |> Map.get(:rt_polled_at, %{}) |> Map.get(url) do
1032 1060 nil -> true
modified apps/room_hermes/lib/room_hermes/mail/imap_worker.ex
+5 −1

Click to load diff…

modified apps/room_icarus/lib/room_icarus/worker.ex
+5 −1

Click to load diff…

modified apps/room_pollen/lib/room_pollen/worker.ex
+5 −1

Click to load diff…

modified apps/room_sanctum/lib/room_sanctum/configuration.ex
+56 −3

Click to load diff…

modified apps/room_sanctum/lib/room_sanctum/workers/ankyra_worker.ex
+4 −1

Click to load diff…

modified apps/room_sanctum/lib/room_sanctum/workers/keryx_worker.ex
+12 −1

Click to load diff…

modified apps/room_sanctum/lib/room_sanctum/workers/pythiae_worker.ex
+12 −1

Click to load diff…

modified apps/room_sanctum/lib/room_sanctum/workers/vision_worker.ex
+12 −1

Click to load diff…

added apps/room_sanctum/test/room_sanctum/config_broadcast_test.exs
+119 −0

Click to load diff…

modified apps/room_treasury/lib/room_treasury/worker.ex
+5 −1

Click to load diff…

modified config/dev.exs
+7 −2

Click to load diff…

Parents: 9c789e8