|
| 1 | +## The contents of this file are subject to the Mozilla Public License |
| 2 | +## Version 1.1 (the "License"); you may not use this file except in |
| 3 | +## compliance with the License. You may obtain a copy of the License |
| 4 | +## at http://www.mozilla.org/MPL/ |
| 5 | +## |
| 6 | +## Software distributed under the License is distributed on an "AS IS" |
| 7 | +## basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See |
| 8 | +## the License for the specific language governing rights and |
| 9 | +## limitations under the License. |
| 10 | +## |
| 11 | +## The Original Code is RabbitMQ. |
| 12 | +## |
| 13 | +## The Initial Developer of the Original Code is GoPivotal, Inc. |
| 14 | +## Copyright (c) 2007-2017 Pivotal Software, Inc. All rights reserved. |
| 15 | + |
| 16 | + |
| 17 | +defmodule RabbitMQ.CLI.Ctl.Commands.ListUnresponsiveQueuesCommand do |
| 18 | + require RabbitMQ.CLI.Ctl.RpcStream |
| 19 | + |
| 20 | + alias RabbitMQ.CLI.Ctl.RpcStream, as: RpcStream |
| 21 | + alias RabbitMQ.CLI.Core.Helpers, as: Helpers |
| 22 | + |
| 23 | + @behaviour RabbitMQ.CLI.CommandBehaviour |
| 24 | + use RabbitMQ.CLI.DefaultOutput |
| 25 | + |
| 26 | + def formatter(), do: RabbitMQ.CLI.Formatters.Table |
| 27 | + |
| 28 | + def scopes(), do: [:ctl, :diagnostics] |
| 29 | + |
| 30 | + def validate(_, _), do: :ok |
| 31 | + |
| 32 | + def merge_defaults(args, opts) do |
| 33 | + {args, Map.merge(default_opts(), opts)} |
| 34 | + end |
| 35 | + |
| 36 | + def switches(), do: [queue_timeout: :integer, local: :boolean] |
| 37 | + |
| 38 | + def usage() do |
| 39 | + "list_unresponsive_queues [--local] [--queue-timeout <queue-timeout>]" |
| 40 | + end |
| 41 | + |
| 42 | + def run([], %{node: node_name, vhost: vhost, timeout: timeout, |
| 43 | + queue_timeout: queue_timeout, local: local_opt}) do |
| 44 | + Helpers.with_nodes_in_cluster(node_name, fn(nodes) -> |
| 45 | + local_mfa = {:rabbit_amqqueue, :emit_unresponsive_local, [vhost, queue_timeout]} |
| 46 | + all_mfa = {:rabbit_amqqueue, :emit_unresponsive, [nodes, vhost, queue_timeout]} |
| 47 | + {chunks, mfas} = case local_opt do |
| 48 | + true -> {1, [local_mfa]}; |
| 49 | + false -> {Kernel.length(nodes), [all_mfa]} |
| 50 | + end |
| 51 | + RpcStream.receive_list_items(node_name, mfas, timeout, [:name], chunks) |
| 52 | + end) |
| 53 | + end |
| 54 | + |
| 55 | + defp default_opts() do |
| 56 | + %{vhost: "/", local: false, queue_timeout: 30000} |
| 57 | + end |
| 58 | + |
| 59 | + def banner(_,%{vhost: vhost}), do: "Listing unresponsive queues for vhost #{vhost} ..." |
| 60 | +end |
0 commit comments