Ash FrameworkAF
Ash Framework3y ago
3 replies
Blibs

How to handle other resource notifications when inside a change?

Here is my change implementation:

defmodule Marketplace.Markets.Property.Offer.Actions.AcceptOffer.Changes.ChangePropertyToPending do
  @moduledoc false

  alias Marketplace.Markets.Property

  use Ash.Resource.Change

  @impl true
  def change(changeset, _, _) do
    Ash.Changeset.before_action(
      changeset,
      fn changeset ->
        property_id = Ash.Changeset.get_data(changeset, :property_id)

        change_property_to_pending!(property_id)

        changeset
      end,
      append?: true
    )
  end

  defp change_property_to_pending!(property_id) do
    %{id: property_id} |> Property.get_any!() |> Property.update!(%{status: :pending})
  end
end


This will run as a change of another resource, as you can see, it basically fetches the resource and updates its status. The problem is that the Property resource also has a pubsub notification for when the update action is called, and I will miss that notification and receive a warning since I'm not handling it here.

My question is, how can I handle the update action notification inside that change?
Was this page helpful?