Last active
August 13, 2018 20:46
-
-
Save tallysmartins/96153a5fe025ee8f13d3c1a375388fed to your computer and use it in GitHub Desktop.
Runner refactoring
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Elixir Bench Runner API | |
defmodule ElixirBench.Runner.Api do | |
@api_client Application.fetch_env(:runner, api_client) | |
#notify caller about submission status | |
def submit_results(caller, credentials, job, results) do | |
case @api_client.submit_results(credentials, results) do | |
:ok -> send(caller, :ok) | |
_ -> send(caller, :error) | |
end | |
end | |
end | |
defmodule ElixirBench.Runner do | |
use GenServer | |
# receiving the task_function as params here, I can change it in tests so it becomes easier | |
defp process_job(job_data, credentials, timeout // @job_timeout, task_fun // &Job.run_job/1) do | |
opts = [timeout: timeout, task_fun: task_fun] | |
job = build_job_struct(job_data) | |
job = Job.start_job(job, opts) | |
data = %{ | |
elixir_version: job.config.elixir_version, | |
erlang_version: job.config.erlang_version, | |
log: job.log || "" | |
} | |
data = Map.merge(data, job.context) | |
# Receiving a message from the Api.submit_results I can assume all the my measurements are resulting in Api calls | |
with {:ok, _} <- Api.submit_results(self(), credentials, job, data), | |
{:ok, _} <- submit_measurements(job, credentials) do | |
_ -> Logger.info("Job processed and results updated") | |
else | |
_ -> Logger.info("Sending results for jobfailed, it will be re-claimed for new execution") | |
end | |
end | |
defp submit_measurements(job, credentials) | |
Enum.each(job.measurements, fn {benchmark_name, metrics} -> | |
{:ok, _} = Api.submit_results(self(), credentials, job, %{measurements: %{benchmark_name => metrics}}) | |
end) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment