Skip to content

Commit 4df56ad

Browse files
tallysmartinsPragTob
authored andcommitted
Adds exit status code to Job (#45)
* Adds exit status code to Job Signed-off-by: Tallys Martins <[email protected]> * Fixes in seeds.exs scripts - Make local calls to github in memory client to fetch config.yml - Adds more jobs samples with different status, aka: success, failure and pending Signed-off-by: Tallys Martins <[email protected]> * Change status of existent jobs to success Signed-off-by: Tallys Martins <[email protected]>
1 parent 424f013 commit 4df56ad

File tree

6 files changed

+53
-7
lines changed

6 files changed

+53
-7
lines changed

lib/elixir_bench/benchmarks/job.ex

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ defmodule ElixirBench.Benchmarks.Job do
1515
field :claimed_at, :utc_datetime
1616
field :completed_at, :utc_datetime
1717
field :log, :string
18+
field :exit_status, :integer
1819

1920
field :branch_name, :string
2021
field :commit_message, :string
@@ -41,7 +42,8 @@ defmodule ElixirBench.Benchmarks.Job do
4142
:cpu_count,
4243
# TODO: change to a string memory
4344
# :memory_mb,
44-
:log
45+
:log,
46+
:exit_status
4547
]
4648

4749
@create_fields [

lib/elixir_bench_web/schema/content_types.ex

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ defmodule ElixirBenchWeb.Schema.ContentTypes do
3535
field :claimed_at, :datetime
3636
field :completed_at, :datetime
3737
field :log, :string
38+
field :exit_status, :integer
3839

3940
field :repo_slug, :string do
4041
resolve(fn %{repo_id: repo_id}, _, %{context: %{loader: loader}} ->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
defmodule ElixirBench.Repo.Migrations.AddExitStatusToJob do
2+
use Ecto.Migration
3+
4+
def change do
5+
alter table(:jobs) do
6+
add :exit_status, :integer, default: nil
7+
end
8+
9+
# assume all existent jobs has finished with success
10+
execute """
11+
UPDATE jobs SET exit_status = 0 WHERE exit_status IS NULL;
12+
""", "" # nothing on down
13+
end
14+
end

priv/repo/seeds.exs

+29-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,29 @@
11
alias ElixirBench.{Benchmarks, Repos}
22

3+
github_client = Application.get_env(:elixir_bench, :github_client)
4+
5+
if(github_client != ElixirBench.Github.ClientInMemory) do
6+
raise """
7+
\n
8+
#############################################################################
9+
Please, before running this seed you need to set :github_client to
10+
ElixirBench.Github.ClientInMemory in your config/mix.#{Mix.env()}
11+
12+
This is necessary because our current scripts are not yet stable enough, so
13+
you need to use local calls to mocked data instead of reaching the Github
14+
servers in order to fetch the config.yml configuration for the repositories.
15+
#############################################################################
16+
"""
17+
end
18+
319
{:ok, runner} = Benchmarks.create_runner(%{name: "test-runner", api_key: "test"})
420
{:ok, repo} = Repos.create_repo(%{owner: "elixir-ecto", name: "ecto"})
521

6-
{:ok, %{id: job_id}} = Benchmarks.create_job(repo, %{branch_name: "mm/benches", commit_sha: "207b2a0"})
22+
{:ok, %{id: job_id1}} = Benchmarks.create_job(repo, %{branch_name: "mm/benches", commit_sha: "207b2a0"})
23+
{:ok, %{id: job_id2}} = Benchmarks.create_job(repo, %{branch_name: "mm/benches", commit_sha: "207b2a0"})
724

8-
{:ok, %{id: ^job_id} = job} = Benchmarks.claim_job(runner)
25+
{:ok, %{id: failed_job_id}} = Benchmarks.create_job(repo, %{branch_name: "mm/benches", commit_sha: "207b2a0"})
26+
{:ok, _pending_job} = Benchmarks.create_job(repo, %{branch_name: "mm/benches", commit_sha: "207b2a0"})
927

1028
data = %{
1129
"elixir_version" => "1.5.2",
@@ -17,6 +35,7 @@ data = %{
1735
"log" => """
1836
[now] Oh how ward it was to run this benchmark!
1937
""",
38+
"exit_status" => 0,
2039
"measurements" => %{
2140
"insert_mysql/insert_plain" => %{
2241
"average" => 393.560253365004,
@@ -73,4 +92,11 @@ data = %{
7392
}
7493
}
7594

76-
:ok = Benchmarks.submit_job(job, data)
95+
{:ok, %{id: ^job_id1} = job1} = Benchmarks.claim_job(runner)
96+
:ok = Benchmarks.submit_job(job1, data)
97+
98+
{:ok, %{id: ^job_id2} = job2} = Benchmarks.claim_job(runner)
99+
:ok = Benchmarks.submit_job(job2, data)
100+
101+
{:ok, %{id: ^failed_job_id} = failed_job} = Benchmarks.claim_job(runner)
102+
:ok = Benchmarks.submit_job(failed_job, %{data | "log" => "Error, exiting with status 127", "exit_status" => 127, "measurements" => nil})

test/elixir_bench_web/schema/schema_test.exs

+5-3
Original file line numberDiff line numberDiff line change
@@ -394,18 +394,20 @@ defmodule ElixirBenchWeb.SchemaTest do
394394

395395
describe "job query" do
396396
test "fetch job by id", context do
397-
job = insert(:job)
397+
job = insert(:job, %{exit_status: 1})
398398

399399
query = """
400400
job (id: "#{job.id}") {
401-
id
401+
id,
402+
exit_status
402403
}
403404
"""
404405

405406
json_data = %{
406407
"data" => %{
407408
"job" => %{
408-
"id" => "#{job.id}"
409+
"id" => "#{job.id}",
410+
"exit_status" => 1
409411
}
410412
}
411413
}

test/support/factory/elixir_bench_factory.ex

+1
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ defmodule ElixirBench.Factory do
106106
"log" => """
107107
[now] Oh how ward it was to run this benchmark!
108108
""",
109+
"exit_status" => 0,
109110
"measurements" => %{
110111
"insert_mysql/insert_plain" => %{
111112
"average" => 393.560253365004,

0 commit comments

Comments
 (0)