Skip to content

Commit

Permalink
Merge pull request #17 from rai200890/fix/dialyzer-warning
Browse files Browse the repository at this point in the history
fix: dialyzer warnings
  • Loading branch information
joaothallis authored Jun 15, 2020
2 parents 999d915 + c97fee3 commit f75f016
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 52 deletions.
3 changes: 2 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ jobs:
- run: mix credo --strict
- run: mix do ecto.create, ecto.migrate
- run: mix coveralls.html
- run: MIX_ENV=dev mix dialyzer --plt
- store_artifacts:
path: cover/

Expand All @@ -44,4 +45,4 @@ workflows:
branches:
only: /.*/
tags:
only: /.*/
only: /.*/
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@ erl_crash.dump
ecto_job_scheduler-*.tar
.elixir_ls/*

# Dialyzer
/priv/plts/*.plt
/priv/plts/*.plt.hash
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.2
1.0.4
103 changes: 55 additions & 48 deletions lib/job.ex
Original file line number Diff line number Diff line change
@@ -1,11 +1,59 @@
defmodule EctoJobScheduler.Job do
@moduledoc """
Defines jobs to be used with EctoJobScheduler.JobQueue and EctoJobScheduler.JobScheduler
Defines jobs to be used with EctoJobScheduler.JobQueue and EctoJobScheduler.JobScheduler.
"""

alias EctoJobScheduler.JobInfo

require Logger

@callback handle_job(%JobInfo{}, params :: map()) :: any()

def handle_job_result(result, original_multi, repo) do
case result do
%Ecto.Multi{} = multi ->
repo.transaction(multi)

:ok ->
repo.transaction(original_multi)
:ok

{:ok, result} ->
repo.transaction(original_multi)
{:ok, result}

other ->
other
end
end

def handle_job_result(:ok, job_name) do
Logger.info("Successfully executed #{job_name}")

{:ok, :ok}
end

def handle_job_result({:ok, successful_changes}, job_name) do
Logger.info("Successfully executed #{job_name}")

{:ok, successful_changes}
end

def handle_job_result({:error, multi_identifier, reason, successful_changes}, job_name) do
Logger.error("Unable to execute #{job_name}",
multi_identifier: multi_identifier,
error: inspect(reason)
)

{:error, multi_identifier, reason, successful_changes}
end

def handle_job_result({:error, reason}, job_name) do
Logger.error("Unable to execute #{job_name}", error: inspect(reason))

{:error, reason}
end

defmacro __using__(options \\ []) do
quote do
require Logger
Expand Down Expand Up @@ -34,58 +82,17 @@ defmodule EctoJobScheduler.Job do

Context.put(job_context)

Logger.info("Attempting to run #{inspect(__MODULE__)} #{attempt} out of #{max_attempts}")

case run_job(job_info, params) do
:ok ->
Logger.info("Successfully executed #{inspect(__MODULE__)}")
{:ok, :ok}

{:ok, successful_changes} ->
Logger.info("Successfully executed #{inspect(__MODULE__)}")

{:ok, successful_changes}

{:error, multi_identifier, reason, successful_changes} ->
Logger.error("Unable to execute #{inspect(__MODULE__)}",
multi_identifier: multi_identifier,
error: inspect(reason)
)

{:error, multi_identifier, reason, successful_changes}
job_name = inspect(__MODULE__)

{:error, reason} ->
Logger.error("Unable to execute #{inspect(__MODULE__)}",
error: inspect(reason)
)
Logger.info("Attempting to run #{job_name} #{attempt} out of #{max_attempts}")

{:error, reason}
end
job_info |> run_job(params) |> EctoJobScheduler.Job.handle_job_result(job_name)
end

defp run_job(%JobInfo{multi: original_multi} = job_info, params) do
case handle_job(job_info, params) do
%Ecto.Multi{} = multi ->
config()[:repo].transaction(multi)

result ->
handle_job_result(original_multi, result)
end
end

defp handle_job_result(original_multi, result) do
case result do
:ok ->
config()[:repo].transaction(original_multi)
:ok

{:ok, result} ->
config()[:repo].transaction(original_multi)
{:ok, result}

other ->
other
end
job_info
|> handle_job(params)
|> EctoJobScheduler.Job.handle_job_result(original_multi, config()[:repo])
end

defp sanitizer do
Expand Down
6 changes: 5 additions & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ defmodule EctoJobScheduler.MixProject do
docs: [
main: "readme",
extras: ["README.md"]
],
dialyzer: [
plt_file: {:no_warn, "priv/plts/dialyzer.plt"},
remove_defaults: [:unknown]
]
]
end
Expand Down Expand Up @@ -55,7 +59,7 @@ defmodule EctoJobScheduler.MixProject do
{:credo, "~> 1.1", only: [:dev, :test], runtime: false},
{:excoveralls, "~> 0.10", only: :test},
{:ex_doc, "~> 0.14", only: :dev, runtime: false},
{:dialyxir, "~> 0.5", only: [:dev], runtime: false}
{:dialyxir, "~> 1.0", only: [:dev], runtime: false}
]
end
end
3 changes: 2 additions & 1 deletion mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
"credo": {:hex, :credo, "1.1.0", "e0c07b2fd7e2109495f582430a1bc96b2c71b7d94c59dfad120529f65f19872f", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "7338d04b30026e30adbcaaedbf0eb7e4d749510d90c2708ff8cc100fa9c8291f"},
"db_connection": {:hex, :db_connection, "2.2.0", "e923e88887cd60f9891fd324ac5e0290954511d090553c415fbf54be4c57ee63", [:mix], [{:connection, "~> 1.0.2", [hex: :connection, repo: "hexpm", optional: false]}], "hexpm", "bdf196feedfa6b83071e808b2b086fb113f8a1c4c7761f6eff6fe4b96aba0086"},
"decimal": {:hex, :decimal, "1.8.1", "a4ef3f5f3428bdbc0d35374029ffcf4ede8533536fa79896dd450168d9acdf3c", [:mix], [], "hexpm", "3cb154b00225ac687f6cbd4acc4b7960027c757a5152b369923ead9ddbca7aec"},
"dialyxir": {:hex, :dialyxir, "0.5.1", "b331b091720fd93e878137add264bac4f644e1ddae07a70bf7062c7862c4b952", [:mix], [], "hexpm", "6c32a70ed5d452c6650916555b1f96c79af5fc4bf286997f8b15f213de786f73"},
"dialyxir": {:hex, :dialyxir, "1.0.0", "6a1fa629f7881a9f5aaf3a78f094b2a51a0357c843871b8bc98824e7342d00a5", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "aeb06588145fac14ca08d8061a142d52753dbc2cf7f0d00fc1013f53f8654654"},
"earmark": {:hex, :earmark, "1.3.2", "b840562ea3d67795ffbb5bd88940b1bed0ed9fa32834915125ea7d02e35888a5", [:mix], [], "hexpm", "e3be2bc3ae67781db529b80aa7e7c49904a988596e2dbff897425b48b3581161"},
"ecto": {:hex, :ecto, "3.3.1", "82ab74298065bf0c64ca299f6c6785e68ea5d6b980883ee80b044499df35aba1", [:mix], [{:decimal, "~> 1.6", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm", "e6c614dfe3bcff2d575ce16d815dbd43f4ee1844599a83de1eea81976a31c174"},
"ecto_job": {:hex, :ecto_job, "3.0.0", "ae3da338fce92d58f76dcaa04400678453298c466897b07f775f646ca16ac41a", [:make, :mix], [{:ecto_sql, "~> 3.2", [hex: :ecto_sql, repo: "hexpm", optional: false]}, {:gen_stage, "~> 0.14", [hex: :gen_stage, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:postgrex, "~> 0.15", [hex: :postgrex, repo: "hexpm", optional: false]}], "hexpm", "fe7795aaeab3d81c0381bcf1aad6484b834e468941fa48f64fa897cfba54538c"},
"ecto_sql": {:hex, :ecto_sql, "3.3.2", "92804e0de69bb63e621273c3492252cb08a29475c05d40eeb6f41ad2d483cfd3", [:mix], [{:db_connection, "~> 2.2", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.3", [hex: :ecto, repo: "hexpm", optional: false]}, {:myxql, "~> 0.3.0", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.15.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "b82d89d4e6a9f7f7f04783b07e8b0af968e0be2f01ee4b39047fe727c5c07471"},
"erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"},
"ex_doc": {:hex, :ex_doc, "0.20.2", "1bd0dfb0304bade58beb77f20f21ee3558cc3c753743ae0ddbb0fd7ba2912331", [:mix], [{:earmark, "~> 1.3", [hex: :earmark, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.10", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm", "8e24fc8ff9a50b9f557ff020d6c91a03cded7e59ac3e0eec8a27e771430c7d27"},
"excoveralls": {:hex, :excoveralls, "0.11.1", "dd677fbdd49114fdbdbf445540ec735808250d56b011077798316505064edb2c", [:mix], [{:hackney, "~> 1.0", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "493daf5a2dd92d022a1c29e7edcc30f1bce1ffe10fb3690fac63889346d3af2f"},
"gen_stage": {:hex, :gen_stage, "0.14.3", "d0c66f1c87faa301c1a85a809a3ee9097a4264b2edf7644bf5c123237ef732bf", [:mix], [], "hexpm", "8453e2289d94c3199396eb517d65d6715ef26bcae0ee83eb5ff7a84445458d76"},
Expand Down

0 comments on commit f75f016

Please sign in to comment.