Skip to content

Commit

Permalink
example errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jessedrelick committed Sep 10, 2024
1 parent 1cda297 commit 0e42d72
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions examples/phoenix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,15 @@ defmodule AgensDemo.MainLive do
@impl true
def handle_info(:job_started, %{assigns: assigns} = socket) do
name = :my_job
Job.run(name, assigns.text)

{:noreply, socket |> assign(:logs, ["Job running: #{name}" | assigns.logs])}
name
|> Job.run(assigns.text)
|> case do
:ok ->
{:noreply, socket |> assign(:logs, ["Job running: #{name}" | assigns.logs])}
{:error, reason} ->
{:noreply, socket |> assign(:logs, ["Job error: #{name}: #{inspect(reason)}" | assigns.logs])}
end
end

@impl true
Expand Down Expand Up @@ -373,6 +379,14 @@ defmodule AgensDemo.MainLive do
socket |> assign(:logs, ["Agens event: job_ended (#{job_name}) #{result}" | assigns.logs])}
end

@impl true
def handle_info({:job_error, {job_name, step_index}, err}, %{assigns: assigns} = socket) do
debug("#{job_name} error (step #{step_index}): #{inspect(err)}")

{:noreply,
socket |> assign(:logs, ["Agens event: job_error (#{job_name}, step #{step_index}) #{inspect(err)}" | assigns.logs])}
end

# Helpers
defp serving() do
{:ok, gpt2} = Bumblebee.load_model({:hf, "openai-community/gpt2"})
Expand Down

0 comments on commit 0e42d72

Please sign in to comment.