Skip to content

Commit

Permalink
Apply format to elixir_bench/benchmarks/
Browse files Browse the repository at this point in the history
Signed-off-by: Tallys Martins <tallysmartins@gmail.com>
  • Loading branch information
tallysmartins authored and PragTob committed May 26, 2018
1 parent 65d7e4f commit 938bf5c
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 27 deletions.
13 changes: 5 additions & 8 deletions .formatter.exs
@@ -1,13 +1,10 @@
# Used by "mix format"
[
inputs: ["mix.exs", "{config,test}/**/*.{ex,exs}"],
#inputs: ["mix.exs", "{config,test,lib/elixir_bench/benchmarks}/**/*.{ex,exs}"],
#inputs: ["mix.exs", "{config,test,lib/elixir_bench/benchmarks,lib/elixir_bench/github}/**/*.{ex,exs}"],
#inputs: ["mix.exs", "{config,test,lib/elixir_bench}/**/*.{ex,exs}"],
#inputs: ["mix.exs", "{config,test,lib/elixir_bench,lib/elixir_bench_web/controllers}/**/*.{ex,exs}"],
#inputs: ["mix.exs", "{config,test,lib/elixir_bench,lib/elixir_bench_web/controllers,lib/elixir_bench_web/schema}/**/*.{ex,exs}"],
#inputs: ["mix.exs", "{config,test,lib/elixir_bench,lib/elixir_bench_web/controllers,lib/elixir_bench_web/schema,lib/elixir_bench_web/views}/**/*.{ex,exs}"],
#inputs: ["mix.exs", "{config,lib,test}/**/*.{ex,exs}"],
inputs: ["mix.exs", "lib/elixir_bench/benchmarks/**/*.{ex,exs}", "{config,test}/**/*.{ex,exs}"],
#inputs: ["mix.exs", "lib/elixir_bench/{benchmarks,github}/**/*.{ex,exs}", "{config,test}/**/*.{ex,exs}"],
#inputs: ["mix.exs", "lib/elixir_bench/**/*.{ex,exs}", "{config,test}/**/*.{ex,exs}"],
#inputs: ["mix.exs","lib/elixir_bench_web/**/*.{ex,exs}", "lib/elixir_bench/**/*.{ex,exs}", "{config,test}/**/*.{ex,exs}"],
#inputs: ["mix.exs","{config,test,lib}/**/*.{ex,exs}"],
locals_without_parens: [
plug: 1,
plug: 2,
Expand Down
4 changes: 2 additions & 2 deletions lib/elixir_bench/benchmarks/benchmark.ex
Expand Up @@ -8,8 +8,8 @@ defmodule ElixirBench.Benchmarks.Benchmark do
schema "benchmarks" do
field :name, :string

belongs_to :repo, Repos.Repo
has_many :measurements, Measurement
belongs_to(:repo, Repos.Repo)
has_many(:measurements, Measurement)

timestamps(type: :utc_datetime)
end
Expand Down
28 changes: 17 additions & 11 deletions lib/elixir_bench/benchmarks/benchmarks.ex
Expand Up @@ -12,7 +12,7 @@ defmodule ElixirBench.Benchmarks do
end

def query(Benchmark, %{repo_id: repo_id}) do
from b in Benchmark, where: b.repo_id == ^repo_id
from(b in Benchmark, where: b.repo_id == ^repo_id)
end

def query(queryable, _args) do
Expand Down Expand Up @@ -65,9 +65,11 @@ defmodule ElixirBench.Benchmarks do

def create_job(repo, attrs) do
changeset = Job.create_changeset(%Job{repo_id: repo.id}, attrs)

with {:ok, job} <- Ecto.Changeset.apply_action(changeset, :insert),
{:ok, raw_config} <- Github.fetch_config(repo.owner, repo.name, job.commit_sha) do
config_changeset = Config.changeset(%Config{}, raw_config)

changeset
|> Ecto.Changeset.put_embed(:config, config_changeset)
|> Repo.insert()
Expand All @@ -94,11 +96,11 @@ defmodule ElixirBench.Benchmarks do

multi
|> Multi.run(benchmark, fn _ ->
{:ok, get_or_create_benchmark!(job.repo_id, name)}
end)
{:ok, get_or_create_benchmark!(job.repo_id, name)}
end)
|> Multi.run({:measurement, name}, fn %{^benchmark => benchmark} ->
create_measurement(benchmark, job, result)
end)
create_measurement(benchmark, job, result)
end)
end)

case Repo.transaction(multi) do
Expand All @@ -123,12 +125,16 @@ defmodule ElixirBench.Benchmarks do

defp fetch_unclaimed_job(runner) do
# Unclaimed or claimed by this runner but not completed
Repo.fetch(from j in Job,
where: is_nil(j.claimed_by) and is_nil(j.claimed_at) and is_nil(j.completed_at),
or_where: j.claimed_by == ^runner.id and not is_nil(j.claimed_at) and is_nil(j.completed_at),
lock: "FOR UPDATE SKIP LOCKED",
order_by: j.inserted_at,
limit: 1
Repo.fetch(
from(
j in Job,
where: is_nil(j.claimed_by) and is_nil(j.claimed_at) and is_nil(j.completed_at),
or_where:
j.claimed_by == ^runner.id and not is_nil(j.claimed_at) and is_nil(j.completed_at),
lock: "FOR UPDATE SKIP LOCKED",
order_by: j.inserted_at,
limit: 1
)
)
end
end
1 change: 1 addition & 0 deletions lib/elixir_bench/benchmarks/config.ex
Expand Up @@ -10,6 +10,7 @@ defmodule ElixirBench.Benchmarks.Config do
field :elixir, :string, default: Confex.fetch_env!(:elixir_bench, :default_elixir_version)
field :erlang, :string, default: Confex.fetch_env!(:elixir_bench, :default_erlang_version)
field :environment, {:map, :string}, default: %{}

embeds_one :deps, Dep, primary_key: false do
embeds_many :docker, Docker, primary_key: {:image, :string, []} do
field :container_name, :string
Expand Down
8 changes: 4 additions & 4 deletions lib/elixir_bench/benchmarks/job.ex
Expand Up @@ -9,8 +9,8 @@ defmodule ElixirBench.Benchmarks.Job do
schema "jobs" do
field :uuid, :binary_id

belongs_to :repo, Repos.Repo
belongs_to :claimant, Runner, foreign_key: :claimed_by
belongs_to(:repo, Repos.Repo)
belongs_to(:claimant, Runner, foreign_key: :claimed_by)
field :claimed_at, :utc_datetime
field :completed_at, :utc_datetime
field :log, :string
Expand All @@ -27,7 +27,7 @@ defmodule ElixirBench.Benchmarks.Job do
field :erlang_version, :string
field :memory_mb, :integer

embeds_one :config, Config
embeds_one(:config, Config)

timestamps()
end
Expand All @@ -45,7 +45,7 @@ defmodule ElixirBench.Benchmarks.Job do

@create_fields [
:branch_name,
:commit_sha,
:commit_sha
]

def claim_changeset(%Job{} = job, claimed_by) do
Expand Down
4 changes: 2 additions & 2 deletions lib/elixir_bench/benchmarks/measurement.ex
Expand Up @@ -4,8 +4,8 @@ defmodule ElixirBench.Benchmarks.Measurement do
alias ElixirBench.Benchmarks.{Benchmark, Job, Measurement}

schema "measurements" do
belongs_to :benchmark, Benchmark
belongs_to :job, Job
belongs_to(:benchmark, Benchmark)
belongs_to(:job, Job)

field :sample_size, :integer
field :mode, :float
Expand Down

0 comments on commit 938bf5c

Please sign in to comment.