Ash FrameworkAF
Ash Framework7mo ago
39 replies
Failz

ash notifier pubsub question

I've got a scenario where pub sub from one resource works, and then another resource where it does not.

in the live view we're subscribed and handling:

def mount(_params, session, socket) do
    Phoenix.PubSub.subscribe(App.PubSub, "budget:#{budget_id}")
end

def handle_info(
        %Phoenix.Socket.Broadcast{
          topic: "budget:" <> budget_id,
          event: _event,
          payload: _data
        },
        socket
      ) do
end


this resource works:

pub_sub do
    module AppWeb.Endpoint
    prefix "budget"

    publish_all :create, [:budget_id] do
      transform & &1.data
    end

    publish_all :update, [:budget_id] do
      transform & &1.data
    end
  end


this one does not:

publish_all :create, [:budget_id] do
      transform fn notification ->
        transfer = notification.data
       
        case App.Finance.get_account(transfer.from_account_id, tenant: transfer.organization_id, authorize?: false) do
          {:ok, account} -> 
            %{notification | data: Map.put(transfer, :budget_id, account.budget_id)}
          {:error, error} -> 
            notification
        end
      end
    end


I've gone a few rounds with the LLM and haven't been able to get this to work. The transform being the thing that's different between the two resources, so I suspect I'm doing something different.
Was this page helpful?