added Conductor that can perform

perform collects all values from each Performance
parent 612eee7d
defmodule Grengine.Conductor do defmodule Grengine.Conductor do
use GenServer use GenServer
alias Grengine.Performance
require Logger require Logger
def start_link, do: GenServer.start_link(__MODULE__, 1000, name: __MODULE__) def start_link, do: GenServer.start_link(__MODULE__, [], name: __MODULE__)
def init(state) do
tick()
{:ok, state} def perform do
end
defp tick, do: Process.send_after(self(), :tick, 1000)
def handle_info(:tick, state) do
Logger.info("handle tick")
get_performances() get_performances()
|> Enum.each( fn perf -> |> Enum.map( fn perf ->
do_performance(perf) do_performance(perf)
end) end)
tick()
{:noreply, state}
end end
def get_performances do def get_performances do
# see https://github.com/paulanthonywilson/gproc_select_examples/blob/master/test/gproc_select_test.exs # see https://github.com/paulanthonywilson/gproc_select_examples/blob/master/test/gproc_select_test.exs
# matcher = :ets.fun2ms(fn x -> x end) # matcher = :ets.fun2ms(fn x -> x end)
...@@ -33,9 +23,11 @@ defmodule Grengine.Conductor do ...@@ -33,9 +23,11 @@ defmodule Grengine.Conductor do
end end
def do_performance(perf) do def do_performance(perf) do
{_, _, name, pid, _} = perf [{_n, _l, {:performance, name}}, _pid, :undefined] = perf
Logger.info(name) Performance.get_values(name)
end end
end end
...@@ -50,5 +50,9 @@ defmodule Grengine.Performance do ...@@ -50,5 +50,9 @@ defmodule Grengine.Performance do
{:reply, Grain.get_values(grain), grain} {:reply, Grain.get_values(grain), grain}
end end
def to_string(performance) do
"Performance"
end
end end
defmodule ConductorTest do
use ExUnit.Case, async: true
alias Grengine.{Conductor, PerformanceSupervisor}
describe "finding all performances" do
setup do
PerformanceSupervisor.start_link
PerformanceSupervisor.start_performance("foo")
PerformanceSupervisor.start_performance("bar")
:ok
end
test "get all running performances" do
foo = Conductor.get_performances()
assert is_list(foo)
assert length(foo) == 2
# assert [{:n, :l, {:performance, "foo"}}] == foo
end
test "handle single performance" do
values = Conductor.perform()
assert is_list(values)
end
end
end
...@@ -14,9 +14,6 @@ defmodule PerformanceTest do ...@@ -14,9 +14,6 @@ defmodule PerformanceTest do
{:ok, perf: perf} {:ok, perf: perf}
end end
test "represents string", %{perf: perf} do
assert Performance.to_string(perf) == "{}"
end
end end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment