@classmethod
  def PushNotification(cls, client, user_id, alert, badge, callback,
                       exclude_device_id=None, extra=None, sound=None):
    """Queries all devices for 'user'. Devices with 'push_token'
    set are pushed notifications via the push_notification API.
    NOTE: currently, code path is synchronous, but the callback
      is provided in case that changes.

    If specified, 'exclude_device_id' will exclude a particular device
    from the set to which notifications are pushed. For example, the
    device which is querying notifications when the badge is set to 0.
    """
    def _OnQuery(devices):
      with util.Barrier(callback) as b:
        now = util.GetCurrentTimestamp()
        for device in devices:
          if device.device_id != exclude_device_id:
            token = device.push_token
            assert token, device
            try:
              PushNotification.Push(token, alert=alert, badge=badge, sound=sound, extra=extra)
            except __HOLE__ as e:
              logging.error('bad push token %s', token)
              Device._HandleBadPushToken(client, token, time.time(), b.Callback())
            except Exception as e:
              logging.warning('failed to push notification to user %d: %s', user_id, e)
              raise

    # Find all devices owned by the user that need to be alerted.
    Device.QueryAlertable(client, user_id, _OnQuery)
dataset/ETHPy150Open viewfinderco/viewfinder/backend/db/device.py/Device.PushNotification