def listen(self): #runs task given, with the yield required to get returned value #equivalent of callback/wait pairing from tornado.gen yield tornado.gen.Task(self.redis.subscribe, self.channel) if not self.redis.subscribed: self.write_message('ERROR IN SUBSCRIPTION') #listen from tornadoredis makes the listen object asynchronous #if using standard redis lib, it blocks while listening self.redis.listen(self.callback) # Try and fight race condition by loading from redis after listen # started need to use std redis lib because tornadoredis is in # subscribed state oldmessages = r_server.lrange(self.channel + ':messages', 0, -1) if oldmessages is not None: for message in oldmessages: self.write_message(message)
""" # Update analysis to done in analysis table SQL = """UPDATE qiita_analysis SET analysis_done = true WHERE analysis_id = %s""" try: pgcursor = postgres.cursor() pgcursor.execute(SQL, (analysis_id,)) postgres.commit() pgcursor.close() except PostgresError, e: pgcursor.close() postgres.rollback() raise RuntimeError("Can't finish off analysis: %s" % e) # Wipe out all messages from redis list so no longer pushed to user for message in r_server.lrange(user + ':messages', 0, -1): if analysis_name in str(message): r_server.lrem(user + ':messages', message) # Finally, push finished state push_notification(user, analysis_name, 'done', 'allcomplete') ################################### # Analysis functions # # ------------------ # # These dummy functions will be # # removed once we can call the # # real QIIME functions # ###################################