Fix polling and acks.
This commit is contained in:
14
api.py
14
api.py
@@ -28,11 +28,8 @@ import config
|
||||
|
||||
|
||||
def CreateChannel(google_user, client, client_address, instance_id, args):
|
||||
instance = models.Instance.FindOrCreate(instance_id)
|
||||
|
||||
if instance.polling:
|
||||
instance.polling = False
|
||||
instance.save()
|
||||
instance = models.Instance.FindOrCreate(instance_id, polling=False)
|
||||
assert not instance.polling
|
||||
|
||||
token = channel.create_channel(
|
||||
client_id=instance_id,
|
||||
@@ -56,11 +53,8 @@ def CreateChannel(google_user, client, client_address, instance_id, args):
|
||||
|
||||
|
||||
def Poll(google_user, client, client_address, instance_id, args):
|
||||
instance = models.Instance.FindOrCreate(instance_id)
|
||||
|
||||
if not instance.polling:
|
||||
instance.polling = True
|
||||
instance.save()
|
||||
instance = models.Instance.FindOrCreate(instance_id, polling=True, active=True)
|
||||
assert instance.polling
|
||||
|
||||
events = []
|
||||
if google_user:
|
||||
|
||||
@@ -101,14 +101,14 @@ class Instance(db.Model):
|
||||
return cls.get_by_key_name(instance_id)
|
||||
|
||||
@classmethod
|
||||
def FindOrCreate(cls, instance_id, polling=False):
|
||||
def FindOrCreate(cls, instance_id, **kwargs):
|
||||
logging.info('Instance: %s', instance_id)
|
||||
return cls.get_or_insert(instance_id, polling=polling)
|
||||
return cls.get_or_insert(instance_id, **kwargs)
|
||||
|
||||
def GetSubscriptions(self):
|
||||
return (
|
||||
Subscription.all()
|
||||
.filter('instance=', self))
|
||||
.filter('instance =', self))
|
||||
|
||||
|
||||
class Subject(db.Model):
|
||||
@@ -412,7 +412,8 @@ class Subscription(db.Model):
|
||||
cls(parent=subject,
|
||||
instance=instance,
|
||||
readable_only_by_me=readable_only_by_me,
|
||||
writable_only_by_me=writable_only_by_me).put()
|
||||
writable_only_by_me=writable_only_by_me,
|
||||
polling=polling).put()
|
||||
return subject.GetEvents(messages, last_id, request)
|
||||
|
||||
@classmethod
|
||||
@@ -432,7 +433,7 @@ class Subscription(db.Model):
|
||||
def SendMessage(self, msg):
|
||||
encoded = json.dumps(msg, default=utils.EncodeJSON)
|
||||
if self.polling:
|
||||
Event(parent=this,
|
||||
Event(parent=self,
|
||||
json=encoded).save()
|
||||
else:
|
||||
instance_key = Subscription.instance.get_value_for_datastore(self)
|
||||
@@ -445,7 +446,7 @@ class Subscription(db.Model):
|
||||
.ancestor(self))
|
||||
ret = []
|
||||
for e in events:
|
||||
if e in acks:
|
||||
if str(e.key()) in acks:
|
||||
e.delete()
|
||||
else:
|
||||
ret.append(e.ToEvent())
|
||||
|
||||
Reference in New Issue
Block a user