Skip to content

Commit

Permalink
Reflect code review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
ono committed Jul 24, 2017
1 parent 62c7f01 commit d3dc0c5
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 21 deletions.
2 changes: 1 addition & 1 deletion lib/task_bunny/config.ex
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ defmodule TaskBunny.Config do
@doc """
Returns the list of failure backends.
It returns [TaskBunny.FailureBackend.Logger] by default.
It returns `TaskBunny.FailureBackend.Logger` by default.
"""
@spec failure_backend :: [atom]
def failure_backend do
Expand Down
4 changes: 1 addition & 3 deletions lib/task_bunny/failure_backend.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
defmodule TaskBunny.FailureBackend do
@moduledoc """
A behaviour module to implment the your own failure backend.
A behaviour module to implement the your own failure backend.
Note the backend is called only for the errors caught during job processing.
Any other errors won't be reported to the backend.
Expand Down Expand Up @@ -49,7 +49,5 @@ defmodule TaskBunny.FailureBackend do
def report_job_error(job_error = %JobError{}) do
Config.failure_backend()
|> Enum.each(&(&1.report_job_error(job_error)))

:ok
end
end
25 changes: 10 additions & 15 deletions lib/task_bunny/failure_backend/logger.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ defmodule TaskBunny.FailureBackend.Logger do
alias TaskBunny.JobError

def report_job_error(error = %JobError{error_type: :exception}) do
message = """
"""
TaskBunny - #{error.job} failed for an exception.
Exception:
Expand All @@ -18,55 +18,50 @@ defmodule TaskBunny.FailureBackend.Logger do
Stacktrace:
#{Exception.format_stacktrace(error.stacktrace)}
"""

do_report(message, error.reject)
|> do_report(error.reject)
end

def report_job_error(error = %JobError{error_type: :return_value}) do
message = """
"""
TaskBunny - #{error.job} failed for an invalid return value.
Return value:
#{my_inspect error.return_value}
#{common_message error}
"""

do_report(message, error.reject)
|> do_report(error.reject)
end

def report_job_error(error = %JobError{error_type: :exit}) do
message = """
"""
TaskBunny - #{error.job} failed for EXIT signal.
Reason:
#{my_inspect error.reason}
#{common_message error}
"""

do_report(message, error.reject)
|> do_report(error.reject)
end

def report_job_error(error = %JobError{error_type: :timeout}) do
message = """
"""
TaskBunny - #{error.job} failed for timeout.
#{common_message error}
"""

do_report(message, error.reject)
|> do_report(error.reject)
end

def report_job_error(error) do
message = """
"""
TaskBunny - Failed with the unknown error type.
Error dump:
#{my_inspect error}
"""

do_report(message, true)
|> do_report(true)
end

defp do_report(message, rejected) do
Expand Down
8 changes: 6 additions & 2 deletions lib/task_bunny/job_error.ex
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ defmodule TaskBunny.JobError do
"""

@type t :: %__MODULE__{
job: atom,
job: atom | nil,
payload: any,
error_type: :exception | :return_value | :timeout | :exit | nil,
exception: struct | nil,
Expand All @@ -34,7 +34,7 @@ defmodule TaskBunny.JobError do
failed_count: integer,
queue: String.t,
concurrency: integer,
pid: pid,
pid: pid | nil,
reject: boolean
}

Expand All @@ -56,6 +56,7 @@ defmodule TaskBunny.JobError do
]

@doc false
@spec handle_exception(atom, any, struct) :: t
def handle_exception(job, payload, exception) do
%__MODULE__{
job: job,
Expand All @@ -67,6 +68,7 @@ defmodule TaskBunny.JobError do
end

@doc false
@spec handle_exit(atom, any, any) :: t
def handle_exit(job, payload, reason) do
%__MODULE__{
job: job,
Expand All @@ -77,6 +79,7 @@ defmodule TaskBunny.JobError do
end

@doc false
@spec handle_return_value(atom, any, any) :: t
def handle_return_value(job, payload, return_value) do
%__MODULE__{
job: job,
Expand All @@ -87,6 +90,7 @@ defmodule TaskBunny.JobError do
end

@doc false
@spec handle_timeout(atom, any) :: t
def handle_timeout(job, payload) do
%__MODULE__{
job: job,
Expand Down

0 comments on commit d3dc0c5

Please sign in to comment.