def fetch_stories(refresh_clients=False): """ fetch userstories from pivotaltracker and add some information into the database. """ redis.flushdb() request = PivotalRequest() pipe = redis.pipeline(transaction=True) for iteration in request.iter_iterations(): iteration_id = iteration['id'] Iteration.create(iteration, pipe=pipe) app.logger.info('Processing iteration: %s', iteration_id) for story in request.iter_stories(iteration['stories']): story_id = story['id'] Story.create(story, pipe=pipe) Iteration.add_story(iteration_id, story_id, pipe=pipe) app.logger.info(story_id) app.logger.info('retrieve stories in the icebox') for story in request.iter_icebox(): story_id = story['id'] Story.create(story, pipe=pipe) app.logger.info(story_id) pipe.execute() if refresh_clients: from wafwfy.events import refresh_clients as refresh_clients_fun refresh_clients_fun()
def add_story(cls, iteration_id, story_id, pipe=None): commit = False if pipe is None: pipe = redis.pipeline(transaction=True) commit = True iteration_key = cls.STORIES_LIST.format(pk=iteration_id) pipe.sadd(iteration_key, story_id) if commit: pipe.execute()
def create(cls, a_dict, pipe=None): commit = False if pipe is None: pipe = redis.pipeline(transaction=True) commit = True the_id = a_dict[cls.PK_ATTRIB] the_key = cls.ENTRY_KEY.format(pk=the_id) pipe.delete(the_key) pipe.set(the_key, json.dumps(a_dict)) pipe.rpush(cls.LIST_KEY, the_id) if cls.STATE_KEY and cls.STATE_ATTRIB: pipe.rpush( cls.STATE_KEY.format(state=a_dict[cls.STATE_ATTRIB]), the_id ) if commit: pipe.execute()