towerops/lib/towerops_web/live/maintenance_live/show.ex
Graham McIntire de986bddf6
Prevent Oban polling/monitoring job stacking per device
When the Oban queue backs up, the 60-second uniqueness window expires
and duplicate jobs stack up per device. Switch to period: :infinity so
only one poll/monitor job exists per device at any time. Add replace
option to supersede stale scheduled jobs with updated scheduled_at.
Remove :executing from unique states so self-scheduling works while
the current job runs. Set max_attempts: 1 since retrying stale polls
is pointless.

Also fix all credo --strict issues across the codebase.
2026-02-16 16:37:48 -06:00

57 lines
1.4 KiB
Elixir

defmodule ToweropsWeb.MaintenanceLive.Show do
@moduledoc false
use ToweropsWeb, :live_view
alias Towerops.Maintenance
@impl true
def mount(%{"id" => id}, _session, socket) do
window = Maintenance.get_window!(id)
timezone = socket.assigns.current_scope.timezone
{:ok,
socket
|> assign(:page_title, window.name)
|> assign(:window, window)
|> assign(:timezone, timezone)}
end
@impl true
def handle_event("delete", _params, socket) do
case Maintenance.delete_window(socket.assigns.window) do
{:ok, _} ->
{:noreply,
socket
|> put_flash(:info, t("Maintenance window deleted"))
|> push_navigate(to: ~p"/maintenance")}
{:error, _} ->
{:noreply, put_flash(socket, :error, t("Unable to delete maintenance window"))}
end
end
defp status_for(window) do
now = DateTime.utc_now()
cond do
DateTime.after?(window.starts_at, now) -> :upcoming
DateTime.before?(window.ends_at, now) -> :past
true -> :active
end
end
defp scope_label(window) do
cond do
window.device -> "Device: #{window.device.name}"
window.site -> "Site: #{window.site.name}"
true -> "Org-wide"
end
end
defp format_datetime(dt, timezone) do
case DateTime.shift_zone(dt, timezone) do
{:ok, local} -> Calendar.strftime(local, "%b %d, %Y %I:%M %p")
_ -> Calendar.strftime(dt, "%b %d, %Y %I:%M %p UTC")
end
end
end