def _listen(self, task_id): # task_ids start at zero, so we gobble up ports starting at the base port and work up port_no = int(config.get("api_base_port")) + task_id # Log according to configured directory and port # we're operating on log_file = "%s/rw_api_%s.log" % (config.get("api_log_dir"), port_no) if config.test_mode and os.path.exists(log_file): os.remove(log_file) log.init(log_file, config.get("log_level")) log.debug("start", "Server booting, port %s." % port_no) db.open() cache.open() for sid in config.station_ids: cache.update_local_cache_for_sid(sid) # If we're not in developer, remove development-related URLs if not config.get("developer_mode"): i = 0 while (i < len(request_classes)): if request_classes[i][0].find("/test/") != -1: request_classes.pop(i) i = i - 1 i = i + 1 # Make sure all other errors get handled in an API-friendly way request_classes.append((r".*", api.web.Error404Handler)) # Initialize the help (rather than it scan all URL handlers every time someone hits it) api.help.sectionize_requests() # Initialize playlist variables playlist.prepare_cooldown_algorithm(sid) # Fire ze missiles! app = tornado.web.Application( request_classes, debug=(config.test_mode or config.get("developer_mode")), template_path=os.path.join(os.path.dirname(__file__), "../templates"), static_path=os.path.join(os.path.dirname(__file__), "../static"), autoescape=None) http_server = tornado.httpserver.HTTPServer(app, xheaders=True) http_server.listen(port_no) if config.get("api_user") and config.get("api_group"): chuser.change_user(config.get("api_user"), config.get("api_group")) for request in request_classes: log.debug("start", " Handler: %s" % str(request)) log.info("start", "API server bootstrapped and ready to go.") self.ioloop = tornado.ioloop.IOLoop.instance() try: self.ioloop.start() finally: self.ioloop.stop() http_server.stop() db.close() log.info("stop", "Server has been shutdown.") log.close()
def _listen(self, task_id): # task_ids start at zero, so we gobble up ports starting at the base port and work up port_no = int(config.get("api_base_port")) + task_id # Log according to configured directory and port # we're operating on log_file = "%s/api%s.log" % (config.get("log_dir"), port_no) if config.test_mode and os.path.exists(log_file): os.remove(log_file) log.init(log_file, config.get("log_level")) log.debug("start", "Server booting, port %s." % port_no) db.open() # Fire ze missiles! app = tornado.web.Application(request_classes) http_server = tornado.httpserver.HTTPServer(app, xheaders = True) http_server.listen(port_no) for request in request_classes: log.debug("start", " Handler: %s" % str(request)) for sid in config.station_ids: cache.update_local_cache_for_sid(sid) log.info("start", "Server bootstrapped and ready to go.") self.ioloop = tornado.ioloop.IOLoop.instance() self.ioloop.start() http_server.stop() log.info("stop", "Server has been shutdown.") log.close()
def start(): db.open() cache.open() if config.test_mode: playlist.remove_all_locks(1) app = tornado.web.Application([ (r"/advance/([0-9]+)", AdvanceScheduleRequest), (r"/refresh/([0-9]+)", RefreshScheduleRequest) ], debug=(config.test_mode or config.get("developer_mode"))) server = tornado.httpserver.HTTPServer(app) server.listen(int(config.get("backend_port")), address='127.0.0.1') if config.get("backend_user") or config.get("backend_group"): chuser.change_user(config.get("backend_user"), config.get("backend_group")) pid = os.getpid() pidfile = open(config.get("backend_pid_file"), 'w') pidfile.write(str(pid)) pidfile.close() schedule.load() log.debug("start", "Backend server bootstrapped, port %s, ready to go." % int(config.get("backend_port"))) for sid in config.station_ids: playlist.prepare_cooldown_algorithm(sid) try: tornado.ioloop.IOLoop.instance().start() finally: db.close()
def get(self, sid): self.success = False self.sid = None if int(sid) in config.station_ids: self.sid = int(sid) else: return try: schedule.advance_station(self.sid) except psycopg2.extensions.TransactionRollbackError as e: if not self.retried: self.retried = True log.warn("backend", "Database transaction deadlock. Re-opening database and setting retry timeout.") db.close() db.open() tornado.ioloop.IOLoop.instance().add_timeout(datetime.timedelta(milliseconds=350), self.get) else: raise if not config.get("liquidsoap_annotations"): self.write(schedule.get_current_file(self.sid)) else: self.write(self._get_annotated(schedule.get_current_event(self.sid))) self.success = True
def get(self, sid): self.success = False self.sid = None if int(sid) in config.station_ids: self.sid = int(sid) else: return try: schedule.advance_station(self.sid) except psycopg2.extensions.TransactionRollbackError as e: if not self.retried: self.retried = True log.warn( "backend", "Database transaction deadlock. Re-opening database and setting retry timeout." ) db.close() db.open() tornado.ioloop.IOLoop.instance().add_timeout( datetime.timedelta(milliseconds=350), self.get) else: raise if not config.get("liquidsoap_annotations"): self.write(schedule.get_current_file(self.sid)) else: self.write( self._get_annotated(schedule.get_current_event(self.sid))) self.success = True
def _listen(self, task_id): # task_ids start at zero, so we gobble up ports starting at the base port and work up port_no = int(config.get("api_base_port")) + task_id # Log according to configured directory and port # we're operating on log_file = "%s/rw_api_%s.log" % (config.get("api_log_dir"), port_no) if config.test_mode and os.path.exists(log_file): os.remove(log_file) log.init(log_file, config.get("log_level")) log.debug("start", "Server booting, port %s." % port_no) db.open() cache.open() for sid in config.station_ids: cache.update_local_cache_for_sid(sid) # If we're not in developer, remove development-related URLs if not config.get("developer_mode"): i = 0 while i < len(request_classes): if request_classes[i][0].find("/test/") != -1: request_classes.pop(i) i = i - 1 i = i + 1 # Make sure all other errors get handled in an API-friendly way request_classes.append((r".*", api.web.Error404Handler)) # Initialize the help (rather than it scan all URL handlers every time someone hits it) api.help.sectionize_requests() # Initialize playlist variables playlist.prepare_cooldown_algorithm(sid) # Fire ze missiles! app = tornado.web.Application( request_classes, debug=(config.test_mode or config.get("developer_mode")), template_path=os.path.join(os.path.dirname(__file__), "../templates"), static_path=os.path.join(os.path.dirname(__file__), "../static"), autoescape=None, ) http_server = tornado.httpserver.HTTPServer(app, xheaders=True) http_server.listen(port_no) if config.get("api_user") and config.get("api_group"): chuser.change_user(config.get("api_user"), config.get("api_group")) for request in request_classes: log.debug("start", " Handler: %s" % str(request)) log.info("start", "API server bootstrapped and ready to go.") self.ioloop = tornado.ioloop.IOLoop.instance() try: self.ioloop.start() finally: self.ioloop.stop() http_server.stop() db.close() log.info("stop", "Server has been shutdown.") log.close()
def start(): log.init(log_file, config.get("log_level")) log.debug("start", "Server booting, port %s." % port_no) db.open() app = tornado.web.Application([(r"/advance/([0-9]+)", AdvanceScheduleRequest)]) server = tornado.httpserver.HTTPServer(app) server.listen(int(config.get("backend_port")), address="127.0.0.1") schedule.load() tornado.ioloop.IOLoop.instance().start()
def start(): db.open() cache.open() if config.test_mode: playlist.remove_all_locks(1) app = tornado.web.Application( [(r"/advance/([0-9]+)", AdvanceScheduleRequest), (r"/refresh/([0-9]+)", RefreshScheduleRequest)], debug=(config.test_mode or config.get("developer_mode"))) server = tornado.httpserver.HTTPServer(app) server.listen(int(config.get("backend_port")), address='127.0.0.1') if config.get("backend_user") or config.get("backend_group"): chuser.change_user(config.get("backend_user"), config.get("backend_group")) pid = os.getpid() pidfile = open(config.get("backend_pid_file"), 'w') pidfile.write(str(pid)) pidfile.close() schedule.load() log.debug( "start", "Backend server bootstrapped, port %s, ready to go." % int(config.get("backend_port"))) for sid in config.station_ids: playlist.prepare_cooldown_algorithm(sid) try: tornado.ioloop.IOLoop.instance().start() finally: db.close()
import os import sys import os from libs import config from libs import db import rainwave.playlist # Step 1: db_init.py # Step 2: rw_scanner.py --full # Step 3: this script # Step 4: CREATE INDEX ON rw_songratings (song_rating_id); if you haven't already config.load() db.open() class R3Song(rainwave.playlist.Song): def load_r3_data(self): r3_data = db.c.fetch_row( "SELECT MIN(song_addedon) AS song_added_on, SUM(song_totalrequests) AS song_request_count, MAX(song_oa_multiplier) AS song_cool_multiply, MAX(song_oa_override) AS song_cool_override, MAX(song_rating_id) AS song_rating_id FROM rw_songs WHERE song_filename = %s GROUP BY song_filename", (self.filename,), ) if not r3_data: return 0 # db.c.update("UPDATE rw_songs SET r4_song_id = %s WHERE song_filename = %s", (self.id, self.filename)) # db.c.update("UPDATE r4_songs SET song_request_count = %s, song_added_on = %s, song_cool_multiply = %s, song_cool_override = %s WHERE song_id = %s", (r3_data['song_request_count'], r3_data['song_added_on'], r3_data['song_cool_multiply'], r3_data['song_cool_override'], self.id)) updated_ratings = db.c.update( "INSERT INTO r4_song_ratings(song_id, song_rating_user, user_id, song_rated_at, song_rated_at_rank, song_rated_at_count, song_fave) "