def write_user_ranking(type, limit): key_name = 'ranking_%s' % type lst = memcache.get(key_name) if not isinstance(lst, list): lst = [] if type == 'call': query = UserStatus.all().order('-call_count') else: query = UserStatus.all().order('-callee_count') for ent in query: name = ent.key().name()[3:] if name in blocklist: continue profile_image_url = ent.profile_image_url if type == 'call': count = ent.call_count else: count = ent.callee_count lst.append( (name, profile_image_url,count) ) limit -= 1 if limit < 0: break memcache.set(key=key_name, value=lst, time=120) for l in lst: self.response.out.write("['%s','%s',%d]," % (l[0], l[1], l[2]))
def get(self, action): if action == 'request': expired = datetime.datetime.now() - datetime.timedelta(minutes=10) expired_tokens = OAuthRequestToken.all().filter('created <', expired).fetch(20) for token in expired_tokens: token.delete() elif action == 'access': expired = datetime.datetime.now() - datetime.timedelta(hours=6) expired_tokens = OAuthAccessToken.all().filter('modified <', expired).fetch(20) q = taskqueue.Queue('background') for i, token in enumerate(expired_tokens): key_name = token.key().name() t = taskqueue.Task(url='/task/access', params=dict(key_name=key_name), countdown=i*2) q.add(t) elif action == 'graph': q = taskqueue.Queue('fastest') t = taskqueue.Task(url='/task/graph') q.add(t) elif action == 'image': expired = datetime.datetime.now() - datetime.timedelta(days=7) expired_tokens = UserStatus.all().filter('profile_image_updated <', expired).fetch(10) q = taskqueue.Queue('background') for i, token in enumerate(expired_tokens): key_name = token.key().name() t = taskqueue.Task(url='/task/image', params=dict(key_name=key_name), countdown=i*2) q.add(t)