@classmethod
  def ApplyAccounting(cls, client, accounting, callback):
    op_id = Operation.GetCurrent().operation_id
    assert op_id is not None, 'accounting update outside an operation'

    def _OnException(accounting, type, value, traceback):
      # Entry was modified between Query and Update. Rerun the entire method.
      Accounting.ApplyAccounting(client, accounting, callback)

    def _OnQueryAccounting(entry):
      if entry is None:
        # No previous entry. Set op_id and set replace to false.
        # We can submit the accounting object directly since it has not been mutated.
        accounting.op_ids = op_id
        with util.Barrier(callback, on_exception=partial(_OnException, accounting)) as b:
          accounting.Update(client, b.Callback(), replace=False)
      else:
        prev_op_ids = entry.op_ids

        # Checks whether the op id has been applied and modifies op_ids accordingly.
        found = entry.IsOpDuplicate(op_id)
        if found:
          # This operation has been applied: skip.
          callback()
          return

        entry.IncrementStatsFrom(accounting)

        # Entry exists: modify the object returned by Query and require that the op_ids
        # field has not changed since. If the existing entry was created by dbchk, it will
        # not have a op_ids field. Setting expected={'op_ids': None} is not equivalent to
        # expected={'op_ids': False}.
        with util.Barrier(callback, on_exception=partial(_OnException, accounting)) as b:
          entry.Update(client, b.Callback(), expected={'op_ids': prev_op_ids or False})

    Accounting.Query(client, accounting.hash_key, accounting.sort_key, None, _OnQueryAccounting, must_exist=False)
Dispatch PostgreSQL async NOTIFY.
dataset/ETHPy150Open viewfinderco/viewfinder/backend/db/accounting.py/Accounting.ApplyAccounting--crossover with--dataset/ETHPy150Open django-ddp/django-ddp/dddp/api.py/DDP.send_notify