added Conductor that can perform

perform collects all values from each Performance
parent 612eee7d
defmodule Grengine.Conductor do
use GenServer
alias Grengine.Performance
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}
end
defp tick, do: Process.send_after(self(), :tick, 1000)
def handle_info(:tick, state) do
Logger.info("handle tick")
def perform do
get_performances()
|> Enum.each( fn perf ->
|> Enum.map( fn perf ->
do_performance(perf)
end)
tick()
{:noreply, state}
end
def get_performances do
# see https://github.com/paulanthonywilson/gproc_select_examples/blob/master/test/gproc_select_test.exs
# matcher = :ets.fun2ms(fn x -> x end)
......@@ -33,9 +23,11 @@ defmodule Grengine.Conductor do
end
def do_performance(perf) do
{_, _, name, pid, _} = perf
Logger.info(name)
[{_n, _l, {:performance, name}}, _pid, :undefined] = perf
Performance.get_values(name)
end
end
......@@ -50,5 +50,9 @@ defmodule Grengine.Performance do
{:reply, Grain.get_values(grain), grain}
end
def to_string(performance) do
"Performance"
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
{:ok, perf: perf}
end
test "represents string", %{perf: perf} do
assert Performance.to_string(perf) == "{}"
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