Ash FrameworkAF
Ash Framework3y ago
8 replies
gordoneliel

How To: Atomic update with a where clause

I'm trying to implement this workflow:
Update a timestamp atomically on an existing record if the new timestamp is greater than the old one, and the old one hasn't changed while im updating it(optimistic update).
I know atomics just dropped on Ash core so wondering if this could be achieved with it.

This is the ash action in question:
    update :mark_as_paid do
      argument :invoice_event_ts, :utc_datetime_usec, allow_nil?: false

      change set_attribute(:invoice_status, :paid)
      change atomic_update(:last_invoice_event_ts, arg(:invoice_event_ts))
    end
Was this page helpful?