Quiet some of the logspam around instances
This commit is contained in:
2
api.py
2
api.py
@@ -134,7 +134,7 @@ def Unpin(google_user, client, instance_id, args):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
models.Subject.FindOrCreate(subject).Unpin(
|
models.Subject.FindOrCreate(subject).Unpin(
|
||||||
client.parent_key(), sender_message_id, instance)
|
client.parent_key(), sender_message_id, instance.key())
|
||||||
except models.AccessDenied:
|
except models.AccessDenied:
|
||||||
logging.exception('Pin access denied')
|
logging.exception('Pin access denied')
|
||||||
return {
|
return {
|
||||||
|
|||||||
11
channel.py
11
channel.py
@@ -28,6 +28,9 @@ class OnChannelConnect(webapp2.RequestHandler):
|
|||||||
def post(self):
|
def post(self):
|
||||||
instance_id = self.request.get('from')
|
instance_id = self.request.get('from')
|
||||||
instance = models.Instance.FromID(instance_id)
|
instance = models.Instance.FromID(instance_id)
|
||||||
|
if not instance:
|
||||||
|
logging.error('Channel opened with invalid instance_id: %s', instance_id)
|
||||||
|
return
|
||||||
instance.active = True
|
instance.active = True
|
||||||
instance.put()
|
instance.put()
|
||||||
|
|
||||||
@@ -36,16 +39,18 @@ class OnChannelDisconnect(webapp2.RequestHandler):
|
|||||||
@utils.local_namespace
|
@utils.local_namespace
|
||||||
def post(self):
|
def post(self):
|
||||||
instance_id = self.request.get('from')
|
instance_id = self.request.get('from')
|
||||||
instance = models.Instance.FromID(instance_id)
|
instance_key = db.Key.from_path('Instance', instance_id)
|
||||||
|
|
||||||
subscriptions = models.Subscription.all().filter('instance =', instance)
|
subscriptions = models.Subscription.all().filter('instance =', instance_key)
|
||||||
for subscription in subscriptions:
|
for subscription in subscriptions:
|
||||||
subscription.delete()
|
subscription.delete()
|
||||||
|
|
||||||
pins = models.Pin.all().filter('instance =', instance)
|
pins = models.Pin.all().filter('instance =', instance_key)
|
||||||
for pin in pins:
|
for pin in pins:
|
||||||
pin.Delete()
|
pin.Delete()
|
||||||
|
|
||||||
|
instance = models.Instance.FromID(instance_id)
|
||||||
|
if instance:
|
||||||
instance.delete()
|
instance.delete()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -253,17 +253,17 @@ class Subject(db.Model):
|
|||||||
subscription.SendMessage(event)
|
subscription.SendMessage(event)
|
||||||
|
|
||||||
@db.transactional(xg=True)
|
@db.transactional(xg=True)
|
||||||
def RemovePin(self, sender, sender_message_id, instance):
|
def RemovePin(self, sender, sender_message_id, instance_key):
|
||||||
# Reload the subject and instance to establish a barrier
|
# Reload the subject and instance to establish a barrier
|
||||||
subject = Subject.get(self.key())
|
subject = Subject.get(self.key())
|
||||||
instance = Instance.get(instance.key())
|
Instance.get(instance_key)
|
||||||
|
|
||||||
pins = (
|
pins = (
|
||||||
Pin.all()
|
Pin.all()
|
||||||
.ancestor(subject)
|
.ancestor(subject)
|
||||||
.filter('sender =', sender)
|
.filter('sender =', sender)
|
||||||
.filter('sender_message_id =', sender_message_id)
|
.filter('sender_message_id =', sender_message_id)
|
||||||
.filter('instance =', instance))
|
.filter('instance =', instance_key))
|
||||||
|
|
||||||
events = []
|
events = []
|
||||||
for pin in pins:
|
for pin in pins:
|
||||||
@@ -272,9 +272,9 @@ class Subject(db.Model):
|
|||||||
|
|
||||||
return (events, list(Subscription.all().ancestor(subject)))
|
return (events, list(Subscription.all().ancestor(subject)))
|
||||||
|
|
||||||
def Unpin(self, sender, sender_message_id, instance):
|
def Unpin(self, sender, sender_message_id, instance_key):
|
||||||
self.VerifyWritable(sender)
|
self.VerifyWritable(sender)
|
||||||
events, subscriptions = self.RemovePin(sender, sender_message_id, instance)
|
events, subscriptions = self.RemovePin(sender, sender_message_id, instance_key)
|
||||||
for event in events:
|
for event in events:
|
||||||
for subscription in subscriptions:
|
for subscription in subscriptions:
|
||||||
subscription.SendMessage(event)
|
subscription.SendMessage(event)
|
||||||
@@ -378,4 +378,6 @@ class Pin(db.Model):
|
|||||||
}
|
}
|
||||||
|
|
||||||
def Delete(self):
|
def Delete(self):
|
||||||
self.parent().Unpin(self.sender, self.sender_message_id, self.instance)
|
self.parent().Unpin(
|
||||||
|
self.sender, self.sender_message_id,
|
||||||
|
Pin.instance.get_value_for_datastore(self))
|
||||||
|
|||||||
Reference in New Issue
Block a user