def advance_station(sid): playlist.prepare_cooldown_algorithm(sid) playlist.clear_updated_albums(sid) # TODO LATER: Make sure we can "pause" the station here to handle DJ interruptions # Requires controlling the streamer itself to some degree and will take more # work on the API than the back-end. current[sid].finish() last_song = current[sid].get_song() if last_song: history[sid].insert(0, last_song) db.c.update("INSERT INTO r4_song_history (sid, song_id) VALUES (%s, %s)", (sid, last_song.id)) while len(history[sid]) > 3: history[sid].pop() # TODO: IMPORTANT: Block currently playing song/album from being selected so there's no "hole" integrate_new_events(sid) sort_next(sid) if len(next[sid]) == 0: _create_elections(sid) current[sid] = next[sid].pop(0) current[sid].start_event()
def advance_station(sid): # This has been necessary during development and debugging. # Do we want to add an "if config.get("developer_mode")" here so it crashes in production and we hunt down the bug? # next[sid] = filter(None, next[sid]) start_time = time.time() playlist.prepare_cooldown_algorithm(sid) playlist.clear_updated_albums(sid) log.debug("advance", "Playlist prepare time: %.6f" % (time.time() - start_time, )) start_time = time.time() current[sid].finish() log.debug("advance", "Current finish time: %.6f" % (time.time() - start_time, )) start_time = time.time() last_song = current[sid].get_song() if last_song: db.c.update( "INSERT INTO r4_song_history (sid, song_id) VALUES (%s, %s)", (sid, last_song.id)) log.debug("advance", "Last song insertion time: %s" % (time.time() - start_time, )) start_time = time.time() history[sid].insert(0, current[sid]) while len(history[sid]) > 5: history[sid].pop() log.debug("advance", "History management: %.6f" % (time.time() - start_time, )) start_time = time.time() integrate_new_events(sid) # If we need some emergency elections here if len(next[sid]) == 0: next[sid].append(_create_election(sid)) else: sort_next(sid) log.debug("advance", "Next event management: %.6f" % (time.time() - start_time, )) start_time = time.time() current[sid] = next[sid].pop(0) current[sid].start_event() log.debug("advance", "Current management: %.6f" % (time.time() - start_time, )) tornado.ioloop.IOLoop.instance().add_timeout( datetime.timedelta(milliseconds=100), lambda: post_process(sid))
def _update_memcache(sid): cache.set_station(sid, "sched_current", current[sid], True) cache.set_station(sid, "sched_next", next[sid], True) cache.set_station(sid, "sched_history", history[sid], True) cache.set_station(sid, "sched_current_dict", current[sid].to_dict(), True) next_dict_list = [] for event in next[sid]: next_dict_list.append(event.to_dict()) cache.set_station(sid, "sched_next_dict", next_dict_list, True) history_dict_list = [] for event in history[sid]: history_dict_list.append(event.to_dict()) cache.set_station(sid, "sched_history_dict", history_dict_list, True) cache.prime_rating_cache_for_events([ current[sid] ] + next[sid] + history[sid]) cache.set_station(sid, "listeners_current", listeners.get_listeners_dict(sid), True) cache.set_station(sid, "album_diff", playlist.get_updated_albums_dict(sid), True) playlist.clear_updated_albums(sid) cache.set_station(sid, "all_albums", playlist.get_all_albums_list(sid), True) cache.set_station(sid, "all_artists", playlist.get_all_artists_list(sid), True)
def advance_station(sid): # This has been necessary during development and debugging. # Do we want to add an "if config.get("developer_mode")" here so it crashes in production and we hunt down the bug? # next[sid] = filter(None, next[sid]) start_time = time.time() playlist.prepare_cooldown_algorithm(sid) playlist.clear_updated_albums(sid) log.debug("advance", "Playlist prepare time: %.6f" % (time.time() - start_time,)) start_time = time.time() current[sid].finish() log.debug("advance", "Current finish time: %.6f" % (time.time() - start_time,)) start_time = time.time() last_song = current[sid].get_song() if last_song: db.c.update("INSERT INTO r4_song_history (sid, song_id) VALUES (%s, %s)", (sid, last_song.id)) log.debug("advance", "Last song insertion time: %s" % (time.time() - start_time,)) start_time = time.time() history[sid].insert(0, current[sid]) while len(history[sid]) > 5: history[sid].pop() log.debug("advance", "History management: %.6f" % (time.time() - start_time,)) start_time = time.time() integrate_new_events(sid) # If we need some emergency elections here if len(next[sid]) == 0: next[sid].append(_create_election(sid)) else: sort_next(sid) log.debug("advance", "Next event management: %.6f" % (time.time() - start_time,)) start_time = time.time() current[sid] = next[sid].pop(0) current[sid].start_event() log.debug("advance", "Current management: %.6f" % (time.time() - start_time,)) tornado.ioloop.IOLoop.instance().add_timeout(datetime.timedelta(milliseconds=100), lambda: post_process(sid))
def _update_memcache(sid): cache.set_station(sid, "sched_current", current[sid], True) cache.set_station(sid, "sched_next", next[sid], True) cache.set_station(sid, "sched_history", history[sid], True) cache.set_station(sid, "sched_current_dict", current[sid].to_dict(), True) next_dict_list = [] for event in next[sid]: next_dict_list.append(event.to_dict()) cache.set_station(sid, "sched_next_dict", next_dict_list, True) history_dict_list = [] for event in history[sid]: history_dict_list.append(event.to_dict()) cache.set_station(sid, "sched_history_dict", history_dict_list, True) cache.prime_rating_cache_for_events([current[sid]] + next[sid] + history[sid]) cache.set_station(sid, "listeners_current", listeners.get_listeners_dict(sid), True) cache.set_station(sid, "album_diff", playlist.get_updated_albums_dict(sid), True) playlist.clear_updated_albums(sid) cache.set_station(sid, "all_albums", playlist.get_all_albums_list(sid), True) cache.set_station(sid, "all_artists", playlist.get_all_artists_list(sid), True)