Tell polling clients when we've recreated their connection and they need to resubscribe.
This commit is contained in:
2
api.py
2
api.py
@@ -75,6 +75,7 @@ def Poll(google_user, client, client_address, instance_id, args):
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
'result': 'ok',
|
'result': 'ok',
|
||||||
|
'new': instance.newly_created,
|
||||||
'events': events,
|
'events': events,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -161,7 +162,6 @@ def Subscribe(google_user, client, client_address, instance_id, args):
|
|||||||
'result': 'access_denied',
|
'result': 'access_denied',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if not instance or not instance.active:
|
if not instance or not instance.active:
|
||||||
# Probably a race with the channel opening
|
# Probably a race with the channel opening
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -104,7 +104,16 @@ class Instance(db.Model):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def FindOrCreate(cls, instance_id, **kwargs):
|
def FindOrCreate(cls, instance_id, **kwargs):
|
||||||
logging.info('Instance: %s', instance_id)
|
logging.info('Instance: %s', instance_id)
|
||||||
return cls.get_or_insert(instance_id, **kwargs)
|
def _FindOrCreate():
|
||||||
|
entity = cls.get_by_key_name(instance_id)
|
||||||
|
if entity:
|
||||||
|
entity.newly_created = False
|
||||||
|
return entity
|
||||||
|
entity = cls(key_name=instance_id, **kwargs)
|
||||||
|
entity.put()
|
||||||
|
entity.newly_created = True
|
||||||
|
return entity
|
||||||
|
return db.run_in_transaction(_FindOrCreate)
|
||||||
|
|
||||||
def Delete(self):
|
def Delete(self):
|
||||||
logging.info('Deleting instance %s', self.key().name())
|
logging.info('Deleting instance %s', self.key().name())
|
||||||
|
|||||||
Reference in New Issue
Block a user