Skip to content

Commit

Permalink
job error
Browse files Browse the repository at this point in the history
  • Loading branch information
jessedrelick committed Sep 10, 2024
1 parent a4633ed commit 1cda297
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
14 changes: 10 additions & 4 deletions lib/agens/job.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,16 @@ defmodule Agens.Job do
Emitted when a job has started.
```
{:job_ended, job.name, :completed | {:error, error}}
{:job_ended, job.name, :completed}
```
Emitted when a job has ended, either due to completion or an error.
Emitted when a job has been completed.
```
{:job_error, {job.name, step_index}, {:error, error}}
```
Emitted when a job has ended due to an error or unhandled exception.
#### Step
```
Expand Down Expand Up @@ -252,15 +258,15 @@ defmodule Agens.Job do
@spec handle_cast({:error, atom()}, State.t()) :: {:stop, :shutdown, State.t()}
def handle_cast({:error, _reason} = err, %State{config: %Config{name: name}} = state) do
new_state = %State{state | status: :error}
send(state.parent, {:job_ended, {name, state.step_index}, err})
send(state.parent, {:job_error, {name, state.step_index}, err})
{:stop, :shutdown, new_state}
end

@doc false
@impl true
@spec terminate(:normal | :shutdown | {term(), list()}, State.t()) :: :ok
def terminate({exception, _}, %State{config: %{name: name}} = state) do
send(state.parent, {:job_ended, {name, state.step_index}, {:error, exception}})
send(state.parent, {:job_error, {name, state.step_index}, {:error, exception}})
:ok
end

Expand Down
4 changes: 2 additions & 2 deletions test/agens/job_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ defmodule Agens.JobTest do
assert_receive {:job_started, ^name}

assert_receive {:step_started, {^name, 0}, nil}
assert_receive {:job_ended, {^name, 0}, {:error, :input_required}}
assert_receive {:job_error, {^name, 0}, {:error, :input_required}}
end
end

Expand Down Expand Up @@ -198,7 +198,7 @@ defmodule Agens.JobTest do
assert_receive {:step_started, {^name, 1}, "E"}
assert_receive {:step_result, {^name, 1}, "E"}

assert_receive {:job_ended, {^name, 1},
assert_receive {:job_error, {^name, 1},
{:error, %RuntimeError{message: "Invalid step index: :invalid"}}}

assert_receive {:DOWN, ^ref, :process, ^pid, _reason}
Expand Down

0 comments on commit 1cda297

Please sign in to comment.