def sched_flush(cls, name): """Tries to schedule a flush of the counter if there isn't any flush set""" interval_num = get_interval_number(datetime.datetime.now(), INTERVAL) task_name = '-'.join([str(el) for el in [cls._get_kind(), name, INTERVAL, interval_num]]) try: deferred.defer(cls.flush_counter, name, _name=task_name, _countdown=random.randint(0, INTERVAL)) except (taskqueue.TaskAlreadyExistsError, taskqueue.TombstonedTaskError): pass
def update_tag_feeds(self): """Update the tag feed for each tags in this Twisk""" # FIXME should be factored with TwiskUser.update_feeds and Tag.sched_flush for tag in self.tags: interval_num = get_interval_number(datetime.datetime.now(), UPDATE_INTERVAL) # Generate task name for this tag and this interval task_name = '-'.join([str(el) for el in [TAG_FEED_NAMESPACE, tag, interval_num]]) try: deferred.defer(Twisk.update_tag_feed, tag, _name=task_name, _countdown=random.randint(0, UPDATE_INTERVAL)) # If this tasks already exists it means that this method has already # been scheduled less than UPDATE_INTERVAL seconds ago except (taskqueue.TaskAlreadyExistsError, taskqueue.TombstonedTaskError): pass
def update_feeds(self): """Update the feeds for all of the user's followers (should be called in a background task)""" for k in self.followers + [self.key]: # For each follower, schedule a task with a name unique for this # user for UPDATE_INTERVAL seconds # interval_num is going to change every UPDATE_INTERVAL seconds interval_num = get_interval_number(datetime.datetime.now(), UPDATE_INTERVAL) # Generate task name for this user and this interval task_name = "-".join([str(el) for el in [USER_FEED_NAMESPACE, k.id(), interval_num]]) try: deferred.defer( TwiskUser.deferred_update_feed, k, _name=task_name, _countdown=random.randint(0, UPDATE_INTERVAL) ) # If this tasks already exists it means that this method has already # been scheduled less than UPDATE_INTERVAL seconds ago except (taskqueue.TaskAlreadyExistsError, taskqueue.TombstonedTaskError): pass