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)
def get(self): logging.debug('Cron job for Glass updates triggered') updates = FitbitStats.gql('WHERE reported = FALSE and steps > 0') for u in updates: userid = u.key().name() logging.debug('Found update for user %s', userid) if util.get_preferences(userid).hourly_updates: _insert_stats_to_glass(userid, u, util.get_fitbit_goals(userid), True) users = OAuthRequestToken.all() for u in users: userid = u.key().name() if util.get_preferences(userid).battery_level: _check_battery_level(userid)