Exemple #1
0
	def get(self):
		self.response.out.write( "cronjob here!<br /><br />" )
		
		clean_invisible = unicode( self.request.get( "clean_invisible" ) )
		if clean_invisible == "yes":
			# Get a location.
			location = Country.get_random_location()
			# Get the locations lowest high score.
			for control in config.VALID_CONTROLS:
				lowest_score = Score.get_lowest_score( control, location )
				if lowest_score is None:
					continue
				self.clean_country( control, location, lowest_score )
		
		flush = unicode( self.request.get( "flush" ) )
		if flush == "yes":
			memcache.flush_all()
		
		reflag_week_shallow = unicode( self.request.get(
			"reflag_week_shallow" ) )
		if reflag_week_shallow == "yes":
			Score.reflag_new_week()
			
			Score._delete_cached_list( "tilt", config.LOCATION_WEEK )
			Score._delete_cached_list( "touch", config.LOCATION_WEEK )
			
			for control in ("tilt", "touch"):
				Score.get_top_list(config.TOP_LIST_LENGTH, control,
					config.LOCATION_WEEK)
		
		clear_world_week_duplicates = unicode( self.request.get(
			"clear_world_week_duplicates" ) )
		if clear_world_week_duplicates == "yes":
			for location in ( config.LOCATION_WORLD, config.LOCATION_WEEK ):
				for control in config.VALID_CONTROLS:
					self.delete_duplicates( control, location )
		
		clear_random_country_duplicates = unicode( self.request.get(
			"clear_random_country_duplicates" ) )
		if clear_random_country_duplicates == "yes":
			location = Country.get_random_location()
			for control in config.VALID_CONTROLS:
				self.delete_duplicates( control, location )
		
		clear_country_duplicates = unicode( self.request.get(
			"clear_country_duplicates" ) )
		if clear_country_duplicates != "":
			for control in config.VALID_CONTROLS:
				self.delete_duplicates( control, clear_country_duplicates )
		
		clear_all_country_duplicates = unicode( self.request.get(
			"clear_all_country_duplicates" ) )
		if clear_all_country_duplicates == "yes":
			start_location = Country.next_country()
			location = start_location
			count = 0
			try:
				while True:
					for control in config.VALID_CONTROLS:
						self.delete_duplicates( control, location )
					location = Country.next_country()
					count += 1
			except DeadlineExceededError, ex:
				logging.error( "CronJob.get: Got DeadlineExceededError. " \
					+ "Managed to clear %d countries from \"%s\" to \"%s\"",
					count, start_location, location )
				return
Exemple #2
0
				count1 += 1
		
		count2 = 0
		for score in fetched:
			if score in to_remove:
				count2 += 1
		
		logging.info( "count1: %d, count2: %d", count1, count2 )
		
		try:
			db.delete( to_remove )
			self.response.out.write(
				"<br />all entities deleted successfully." )
		except Exception, msg:
			self.response.out.write( "<br />Got exception: '%s'." % msg \
				+ "<br />Some or all deletes might have failed." )
		
		if len(to_remove) > 0:
			# Clear the old lists.
			Score._delete_cached_list( control, location )
			# Request new lists so that they're cached.
			Score.get_top_list( config.TOP_LIST_LENGTH, control, location )

application = webapp.WSGIApplication( [ ( "/cronjob", CronJob ) ] )

def main():
	run_wsgi_app( application )

if __name__ == "__main__":
	main()