Skip to content

Commit

Permalink
Merge pull request #3918 from nulib/4529-ark-notification-logging
Browse files Browse the repository at this point in the history
Add more logging to ARK listener
  • Loading branch information
mbklein authored Apr 24, 2024
2 parents 65adc78 + c4b7a98 commit a3bb18a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
18 changes: 13 additions & 5 deletions app/lib/meadow/ark_listener.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,25 @@ defmodule Meadow.ArkListener do

@impl true
def handle_notification(:works, :delete, %{id: id}, state) do
Arks.work_deleted(id)
{:noreply, state}
with_log_metadata module: __MODULE__, id: id do
Logger.info("Received DELETE notification for ARK on work #{id}")
Arks.work_deleted(id)
{:noreply, state}
end
end

def handle_notification(:works, :insert, %{id: id}, state) do
Works.get_work(id) |> Arks.mint_ark()
{:noreply, state}
with_log_metadata module: __MODULE__, id: id do
Logger.info("Received INSERT notification for ARK on work #{id}")
Works.get_work(id) |> Arks.mint_ark()
{:noreply, state}
end
end

def handle_notification(:works, _op, %{id: id}, state) do
def handle_notification(:works, op, %{id: id}, state) do
with_log_metadata module: __MODULE__, id: id do
Logger.info("Received #{String.upcase(to_string(op))} notification for ARK on work #{id}")

case Works.get_work!(id) do
nil -> :noop
work -> update_ark_metadata(work)
Expand Down
6 changes: 6 additions & 0 deletions app/lib/meadow/utils/arks.ex
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,18 @@ defmodule Meadow.Arks do
"""
def mint_ark(%Work{descriptive_metadata: %{ark: ark}} = work)
when not is_nil(ark) do
Logger.warn("Not minting ARK for work #{work.id} because it already has one: #{ark}")
{:noop, work}
end

def mint_ark(nil), do: {:noop, nil}

def mint_ark(%Work{} = work) do
Logger.info("Minting ARK for work #{work.id}")

case work |> initial_ark() |> Ark.mint() do
{:ok, result} ->
Logger.info("Minted ARK #{result.ark} for work #{work.id}")
Works.update_work(work, %{descriptive_metadata: %{ark: result.ark}})

{:error, error_message} ->
Expand Down Expand Up @@ -106,6 +110,8 @@ defmodule Meadow.Arks do
end

defp update_existing_ark(work, _, ark) do
Logger.info("Updating ARK #{ark.ark} for work #{work.id}")

case Ark.put(ark) do
{:ok, result} ->
Logger.info("Ark successfully updated. #{inspect(result)}")
Expand Down

0 comments on commit a3bb18a

Please sign in to comment.