Esempio n. 1
0
	def remove_from_sessions(self, channel_id):
		# Get session
		session = Session.get_by_key_name(channel_id)
		extended_session = None
		
		if(session):
			session.ended = datetime.utcnow()
			session.put()
			logging.info("Session ended in datastore")
		
			# Init listener
			listener = session.listener

			# Init extended session
			extended_session = Session.get_extended_session(session, listener)
		
			new_sessions = []
			for s in self.sessions:
				if s["key_name"] != channel_id:
					new_sessions.append(s)
		
			memcache.set(self._memcache_station_sessions_id, new_sessions)
			logging.info("Session removed from memcache")
			
			# Online status becomes false if listener = host + no other host listening
			if(listener and listener.key().name() == Session.host.get_value_for_datastore(session).name()):
				logging.info("Admin leaves")
				
				still_some_admins = False
				for s in new_sessions:
					if(s["listener_key_name"] == str(listener.key().name())):
						still_some_admins = True
						break
				
				if not still_some_admins:
					self.station.online = False
					self.station.put()
					logging.info("Station updated in datastore")
										
					memcache.set(self._memcache_station_id, self.station)
					logging.info("Station updated in memcache")
				else:
					logging.info("Still some admins online")
				
		return extended_session
Esempio n. 2
0
	def add_to_sessions(self, channel_id):
		# Get session
		session = Session.get_by_key_name(channel_id)
		extended_session = None
		
		if(session):	
			# After a reconnection the session may have ended. Correct it.
			if session.ended is not None:
				session.ended = None
				session.put()
				logging.info("Session had ended (probable reconnection). Corrected session put.")
	
			# Init listener
			listener = session.listener
			
			# Init extended session
			extended_session = Session.get_extended_session(session, listener)
	
			new_sessions = self.sessions
			new_sessions.append(extended_session)
			memcache.set(self._memcache_station_sessions_id, new_sessions)
			logging.info("Session added in memcache")
			
			# Online status becomes true if listener = host
			if(listener and listener.key().name() == Session.host.get_value_for_datastore(session).name()):
				logging.info("Admin joins")	
				
				self.station.online = True
				self.station.active = datetime.utcnow()
				self.station.put()
				logging.info("Station updated in datastore")
				
				memcache.set(self._memcache_station_id, self.station)
				logging.info("Station updated in memcache")
			
		return extended_session