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 reset_schedule(sid): # Reset the schedule schedule.current = {} schedule.upnext = {} schedule.history = {} cache.set_station(sid, "sched_current", None, True) cache.set_station(sid, "sched_next", None, True) cache.set_station(sid, "sched_history", None, True) playlist.remove_all_locks(1)
def _listen(self, sid): pid = os.getpid() pid_file = open( "%s/backend_%s.pid" % ( config.get_directory("pid_dir"), config.station_id_friendly[sid].lower(), ), "w", ) pid_file.write(str(pid)) pid_file.close() db.connect() cache.connect() zeromq.init_pub() log.init( "%s/rw_%s.log" % ( config.get_directory("log_dir"), config.station_id_friendly[sid].lower(), ), config.get("log_level"), ) memory_trace.setup(config.station_id_friendly[sid].lower()) if config.test_mode: playlist.remove_all_locks(sid) # (r"/refresh/([0-9]+)", RefreshScheduleRequest) app = tornado.web.Application( [ (r"/advance/([0-9]+)", AdvanceScheduleRequest), ], debug=(config.test_mode or config.get("developer_mode")), ) port = int(config.get("backend_port")) + sid server = tornado.httpserver.HTTPServer(app) server.listen(port, address="127.0.0.1") for station_id in config.station_ids: playlist.prepare_cooldown_algorithm(station_id) schedule.load() log.debug( "start", "Backend server started, station %s port %s, ready to go." % (config.station_id_friendly[sid], port), ) ioloop = tornado.ioloop.IOLoop.instance() try: ioloop.start() finally: ioloop.stop() server.stop() db.close() log.info("stop", "Backend has been shutdown.") log.close()
def test_fill(self): e = Election.create(1) e.fill() e2 = Election.load_by_id(e.id) self.assertEqual(e.id, e2.id) e2 = Election.load_by_type(1, e.type) self.assertEqual(e.type, e2.type) unused_elecs = Election.load_unused(1) fail = True for unused_elec in unused_elecs: if e.id == unused_elec.id: fail = False self.assertEqual(False, fail) playlist.remove_all_locks(1) e = Election.create(1) e.fill(5) playlist.remove_all_locks(1)
def test_fill_and_load(self): e = Election.create(1) self.assertEqual(e.use_crossfade, True) e.fill() e2 = Election.load_by_id(e.id) self.assertEqual(e2.use_crossfade, True) self.assertEqual(e.id, e2.id) e2 = Election.load_by_type(1, e.type) self.assertEqual(e2.use_crossfade, True) self.assertEqual(e.type, e2.type) unused_elecs = Election.load_unused(1) fail = True for unused_elec in unused_elecs: if e.id == unused_elec.id: fail = False self.assertEqual(False, fail) playlist.remove_all_locks(1) e = Election.create(1) e.fill(5) playlist.remove_all_locks(1)
def _listen(self, sid): pid = os.getpid() pid_file = open("%s/backend_%s.pid" % (config.get_directory("pid_dir"), config.station_id_friendly[sid].lower()), 'w') pid_file.write(str(pid)) pid_file.close() db.connect() cache.connect() zeromq.init_pub() log.init("%s/rw_%s.log" % (config.get_directory("log_dir"), config.station_id_friendly[sid].lower()), config.get("log_level")) memory_trace.setup(config.station_id_friendly[sid].lower()) if config.test_mode: playlist.remove_all_locks(sid) # (r"/refresh/([0-9]+)", RefreshScheduleRequest) app = tornado.web.Application([ (r"/advance/([0-9]+)", AdvanceScheduleRequest), ], debug=(config.test_mode or config.get("developer_mode"))) port = int(config.get("backend_port")) + sid server = tornado.httpserver.HTTPServer(app) server.listen(port, address='127.0.0.1') for station_id in config.station_ids: playlist.prepare_cooldown_algorithm(station_id) schedule.load() log.debug("start", "Backend server started, station %s port %s, ready to go." % (config.station_id_friendly[sid], port)) ioloop = tornado.ioloop.IOLoop.instance() try: ioloop.start() finally: ioloop.stop() server.stop() db.close() log.info("stop", "Backend 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()