From 164c2040d1b14a2cf1f377627fe86cd594af4e00 Mon Sep 17 00:00:00 2001 From: Anantha Kumaran Date: Sun, 13 Mar 2022 13:26:02 +0530 Subject: [PATCH] Add toggle switch per node to unsubscibe from all queues --- lib/exq_ui/queue.ex | 4 ++++ lib/exq_ui_web/live/busy_live/index.ex | 22 +++++++++++++++++++ lib/exq_ui_web/live/busy_live/index.html.heex | 9 +++++++- mix.exs | 2 +- mix.lock | 4 ++-- test/exq_ui_web/live/busy_live/index_test.exs | 13 +++++++++++ 6 files changed, 50 insertions(+), 4 deletions(-) diff --git a/lib/exq_ui/queue.ex b/lib/exq_ui/queue.ex index 240f9e4..415e40d 100644 --- a/lib/exq_ui/queue.ex +++ b/lib/exq_ui/queue.ex @@ -215,6 +215,10 @@ defmodule ExqUI.Queue do processes end + def send_signal(node_id, signal_name) do + Api.send_signal(api(), node_id, signal_name) + end + defp decode_jobs_with_score(jobs) do Enum.map(jobs, fn {json, score} -> job_with_score(json, score) diff --git a/lib/exq_ui_web/live/busy_live/index.ex b/lib/exq_ui_web/live/busy_live/index.ex index 50ccbfd..ba71e9c 100644 --- a/lib/exq_ui_web/live/busy_live/index.ex +++ b/lib/exq_ui_web/live/busy_live/index.ex @@ -7,4 +7,26 @@ defmodule ExqUIWeb.BusyLive.Index do def mount(_params, _session, socket) do {:ok, assign(socket, %{nodes: Queue.list_nodes(), jobs: Queue.list_current_jobs()})} end + + @impl true + def handle_event( + "signal", + %{"signal" => %{"name" => "TSTP", "node_id" => node_id}}, + socket + ) do + :ok = Queue.send_signal(node_id, "TSTP") + + nodes = + Enum.map(socket.assigns.nodes, fn node -> + if node.identity == node_id do + %{node | quiet: true} + else + node + end + end) + + socket = assign(socket, :nodes, nodes) + + {:noreply, socket} + end end diff --git a/lib/exq_ui_web/live/busy_live/index.html.heex b/lib/exq_ui_web/live/busy_live/index.html.heex index 67d219f..c0e99e3 100644 --- a/lib/exq_ui_web/live/busy_live/index.html.heex +++ b/lib/exq_ui_web/live/busy_live/index.html.heex @@ -12,7 +12,14 @@ <%= for node <- @nodes do %> - <%= node.identity %>
+
+ <%= node.identity %> + <%= form_for :signal, "#", [id: "node-#{node.identity}", phx_change: :signal, class: "mb-0 form-check form-switch form-check-inline"], fn f -> %> + <%= hidden_input(f, :name, value: "TSTP") %> + <%= hidden_input(f, :node_id, value: node.identity) %> + <%= checkbox(f, :quiet, value: !node.quiet, disabled: node.quiet, class: "form-check-input", role: "switch", title: "quiet") %> + <% end %> +
Queues: <%= Enum.join(node.queues, ", ") %> <%= human_time(node.started_at) %> diff --git a/mix.exs b/mix.exs index daa38a9..f520422 100644 --- a/mix.exs +++ b/mix.exs @@ -30,7 +30,7 @@ defmodule ExqUI.MixProject do defp deps do [ - {:exq, ">= 0.9.0"}, + {:exq, github: "akira/exq", branch: "master"}, {:phoenix_live_view, "~> 0.16"}, {:phoenix_live_reload, "~> 1.2", only: :dev}, {:jason, "~> 1.0"}, diff --git a/mix.lock b/mix.lock index e45299c..3975bb7 100644 --- a/mix.lock +++ b/mix.lock @@ -7,7 +7,7 @@ "earmark_parser": {:hex, :earmark_parser, "1.4.18", "e1b2be73eb08a49fb032a0208bf647380682374a725dfb5b9e510def8397f6f2", [:mix], [], "hexpm", "114a0e85ec3cf9e04b811009e73c206394ffecfcc313e0b346de0d557774ee97"}, "elixir_uuid": {:hex, :elixir_uuid, "1.2.1", "dce506597acb7e6b0daeaff52ff6a9043f5919a4c3315abb4143f0b00378c097", [:mix], [], "hexpm", "f7eba2ea6c3555cea09706492716b0d87397b88946e6380898c2889d68585752"}, "ex_doc": {:hex, :ex_doc, "0.26.0", "1922164bac0b18b02f84d6f69cab1b93bc3e870e2ad18d5dacb50a9e06b542a3", [:mix], [{:earmark_parser, "~> 1.4.0", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "2775d66e494a9a48355db7867478ffd997864c61c65a47d31c4949459281c78d"}, - "exq": {:hex, :exq, "0.16.0", "c17b73960b709885792739c8dede87133174b254ddf3c0c9a0afddfe230a69c5", [:mix], [{:elixir_uuid, ">= 1.2.0", [hex: :elixir_uuid, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:poison, ">= 1.2.0 and < 5.0.0", [hex: :poison, repo: "hexpm", optional: true]}, {:redix, ">= 0.9.0", [hex: :redix, repo: "hexpm", optional: false]}], "hexpm", "9db09532a9cab38142d01eef4621e7a8367e293d89da54f3d15fd820f26313d0"}, + "exq": {:git, "https://github.com/akira/exq.git", "f80d8c9c7143e80b99091709b40efde4d90ef1e6", [branch: "master"]}, "file_system": {:hex, :file_system, "0.2.10", "fb082005a9cd1711c05b5248710f8826b02d7d1784e7c3451f9c1231d4fc162d", [:mix], [], "hexpm", "41195edbfb562a593726eda3b3e8b103a309b733ad25f3d642ba49696bf715dc"}, "floki": {:hex, :floki, "0.31.0", "f05ee8a8e6a3ced4e62beeb2c79a63bc8e12ab98fbaaf6e6a3d9b76b1278e23f", [:mix], [{:html_entities, "~> 0.5.0", [hex: :html_entities, repo: "hexpm", optional: false]}], "hexpm", "b05afa372f5c345a5bf240ac25ea1f0f3d5fcfd7490ac0beeb4a203f9444891e"}, "gettext": {:hex, :gettext, "0.18.2", "7df3ea191bb56c0309c00a783334b288d08a879f53a7014341284635850a6e55", [:mix], [], "hexpm", "f9f537b13d4fdd30f3039d33cb80144c3aa1f8d9698e47d7bcbcc8df93b1f5c5"}, @@ -29,7 +29,7 @@ "plug_cowboy": {:hex, :plug_cowboy, "2.5.2", "62894ccd601cf9597e2c23911ff12798a8a18d237e9739f58a6b04e4988899fe", [:mix], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:cowboy_telemetry, "~> 0.3", [hex: :cowboy_telemetry, repo: "hexpm", optional: false]}, {:plug, "~> 1.7", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "ea6e87f774c8608d60c8d34022a7d073bd7680a0a013f049fc62bf35efea1044"}, "plug_crypto": {:hex, :plug_crypto, "1.2.2", "05654514ac717ff3a1843204b424477d9e60c143406aa94daf2274fdd280794d", [:mix], [], "hexpm", "87631c7ad914a5a445f0a3809f99b079113ae4ed4b867348dd9eec288cecb6db"}, "ranch": {:hex, :ranch, "1.8.0", "8c7a100a139fd57f17327b6413e4167ac559fbc04ca7448e9be9057311597a1d", [:make, :rebar3], [], "hexpm", "49fbcfd3682fab1f5d109351b61257676da1a2fdbe295904176d5e521a2ddfe5"}, - "redix": {:hex, :redix, "1.1.4", "d66fc83d2d4f136c838568d1ec8b0c1a72acfcecfac88a40f86f60aaee883c93", [:mix], [{:castore, "~> 0.1.0", [hex: :castore, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "515eff055b7de8967e835f4de22a6cfe8311bc1b8fe72f48200238fb43f6a803"}, + "redix": {:hex, :redix, "1.1.5", "6fc460d66a5c2287e83e6d73dddc8d527ff59cb4d4f298b41e03a4db8c3b2bd5", [:mix], [{:castore, "~> 0.1.0", [hex: :castore, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "679afdd4c14502fe9c11387ff1cdcb33065a1cf511097da1eee407f17c7a418b"}, "telemetry": {:hex, :telemetry, "0.4.3", "a06428a514bdbc63293cd9a6263aad00ddeb66f608163bdec7c8995784080818", [:rebar3], [], "hexpm", "eb72b8365ffda5bed68a620d1da88525e326cb82a75ee61354fc24b844768041"}, "telemetry_metrics": {:hex, :telemetry_metrics, "0.6.1", "315d9163a1d4660aedc3fee73f33f1d355dcc76c5c3ab3d59e76e3edf80eef1f", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "7be9e0871c41732c233be71e4be11b96e56177bf15dde64a8ac9ce72ac9834c6"}, "telemetry_poller": {:hex, :telemetry_poller, "0.5.1", "21071cc2e536810bac5628b935521ff3e28f0303e770951158c73eaaa01e962a", [:rebar3], [{:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "4cab72069210bc6e7a080cec9afffad1b33370149ed5d379b81c7c5f0c663fd4"}, diff --git a/test/exq_ui_web/live/busy_live/index_test.exs b/test/exq_ui_web/live/busy_live/index_test.exs index b357d06..f490746 100644 --- a/test/exq_ui_web/live/busy_live/index_test.exs +++ b/test/exq_ui_web/live/busy_live/index_test.exs @@ -9,4 +9,17 @@ defmodule ExqUIWeb.BusyLive.IndexTest do assert html =~ ~r/790fa550-08a4-42de-93e4-8c09c867befe/ assert html =~ ~r/0aec2714-9032-4574-ae45-a2037c874d9f/ end + + test "quiet", %{conn: conn} do + {:ok, view, _} = live(conn, "/busy") + + html = render(view) + refute html =~ ~S(disabled="disabled") + + html = + element(view, "#node-anantha-ubuntu") + |> render_change(%{}) + + assert html =~ ~S(disabled="disabled") + end end