/
exceptions.ex
50 lines (36 loc) 路 1.15 KB
/
exceptions.ex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
defmodule Oban.CrashError do
@moduledoc """
Wraps unhandled exits and throws that occur during job execution.
"""
defexception [:message, :reason]
@impl Exception
def exception({kind, reason, stacktrace}) do
message = Exception.format_banner(kind, reason, stacktrace)
%__MODULE__{message: message, reason: reason}
end
end
defmodule Oban.PerformError do
@moduledoc """
Wraps the reason returned by `{:error, reason}`, `{:discard, reason}` in a proper exception.
The original return tuple is available in the `:reason` key.
"""
alias Oban.Worker
defexception [:message, :reason]
@impl Exception
def exception({worker, reason}) do
message = "#{Worker.to_string(worker)} failed with #{inspect(reason)}"
%__MODULE__{message: message, reason: reason}
end
end
defmodule Oban.TimeoutError do
@moduledoc """
Returned when a job is terminated early due to a custom timeout.
"""
alias Oban.Worker
defexception [:message, :reason]
@impl Exception
def exception({worker, timeout}) do
message = "#{Worker.to_string(worker)} timed out after #{timeout}ms"
%__MODULE__{message: message, reason: :timeout}
end
end