Current section
Files
Jump to
Current section
Files
lib/mix/tasks/mete.stress.ex
defmodule Mix.Tasks.Mete.Stress do
use Mix.Task
defmodule StressSupervisor do
@moduledoc false
use Supervisor
alias Mix.Tasks.Mete.Stress.StressProcess
def start_link(init_arg) do
Supervisor.start_link(__MODULE__, init_arg, name: __MODULE__)
end
@impl true
def init(_init_arg) do
children =
for n <- 1..10 do
{StressProcess, [id: n]}
end
Supervisor.init(children, strategy: :one_for_one)
end
end
defmodule StressProcess do
def child_spec(opts) do
%{
id: :"stress_process_#{opts[:id]}",
start: {__MODULE__, :start_link, [opts]},
type: :worker,
restart: :permanent,
shutdown: :infinity
}
end
def start_link(opts) do
{:ok, Process.spawn(fn -> run({opts[:id], 0}) end, [:link])}
end
def run({id, rec}) do
require Logger
Process.sleep(10)
# Mete.write("stress", , fields)
Logger.debug("ping #{rec} from #{id}")
run({id, rec + 1})
end
end
@shortdoc "Transmits Measurements"
@moduledoc """
Transmits Measurements to Tests the configuration
"""
def run(args) do
Supervisor.start_link(StressSupervisor, [])
Mix.Tasks.Run.run(run_args() ++ args)
end
defp run_args do
if iex_running?(), do: [], else: ["--no-halt"]
end
defp iex_running? do
Code.ensure_loaded?(IEx) and IEx.started?()
end
end