예제 #1
0
파일: schedule.py 프로젝트: Sicno/rainwave
def post_process(sid):
	try:
		db.c.start_transaction()
		start_time = time.time()
		playlist.prepare_cooldown_algorithm(sid)
		rainwave.playlist_objects.album.clear_updated_albums(sid)
		log.debug("post", "Playlist prepare time: %.6f" % (time.time() - start_time,))

		start_time = time.time()
		current[sid].finish()
		log.debug("post", "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("post", "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("post", "History management: %.6f" % (time.time() - start_time,))

		start_time = time.time()
		current[sid] = upnext[sid].pop(0)
		current[sid].start_event()
		log.debug("advance", "Current management: %.6f" % (time.time() - start_time,))

		start_time = time.time()
		playlist.warm_cooled_songs(sid)
		playlist.warm_cooled_albums(sid)
		log.debug("advance", "Cooldown warming: %.6f" % (time.time() - start_time,))

		start_time = time.time()
		_add_listener_count_record(sid)
		_trim(sid)
		user.trim_listeners(sid)
		cache.update_user_rating_acl(sid, history[sid][0].get_song().id)
		user.unlock_listeners(sid)
		log.debug("advance", "User management and trimming: %.6f" % (time.time() - start_time,))

		start_time = time.time()
		# reduce song blocks has to come first, otherwise it wll reduce blocks generated by _create_elections
		playlist.reduce_song_blocks(sid)
		# update_cache updates both the line and expiry times
		# this is expensive and not necessary to do more than once
		# DO THIS AFTER EVERYTHING ELSE, RIGHT BEFORE NEXT MANAGEMENT, OR PEOPLE'S REQUESTS SLIP THROUGH THE CRACKS
		request.update_cache(sid)
		# add to the event list / update start times for events
		manage_next(sid)
		log.debug("advance", "Request and upnext management: %.6f" % (time.time() - start_time,))

		update_memcache(sid)
		sync_to_front.sync_frontend_all(sid)
		db.c.commit()
	except:
		db.c.rollback()
		raise
예제 #2
0
파일: schedule.py 프로젝트: Reani/rainwave
def post_process(sid):
	start_time = time.time()
	set_next_start_times(sid)
	request.update_line(sid)
	playlist.reduce_song_blocks(sid)
	_create_elections(sid)

	_add_listener_count_record(sid)
	cache.update_user_rating_acl(sid, history[sid][0].get_song().id)
	_trim(sid)
	user.trim_listeners(sid)
	user.unlock_listeners(sid)
	playlist.warm_cooled_songs(sid)
	playlist.warm_cooled_albums(sid)

	_update_memcache(sid)
	sync_to_front.sync_frontend_all(sid)
	log.debug("post", "Post-processing prepare time: %.6f" % (time.time() - start_time,))
예제 #3
0
파일: schedule.py 프로젝트: Reani/rainwave
def post_process(sid):
    start_time = time.time()
    set_next_start_times(sid)
    request.update_line(sid)
    playlist.reduce_song_blocks(sid)
    _create_elections(sid)

    _add_listener_count_record(sid)
    cache.update_user_rating_acl(sid, history[sid][0].get_song().id)
    _trim(sid)
    user.trim_listeners(sid)
    user.unlock_listeners(sid)
    playlist.warm_cooled_songs(sid)
    playlist.warm_cooled_albums(sid)

    _update_memcache(sid)
    sync_to_front.sync_frontend_all(sid)
    log.debug(
        "post",
        "Post-processing prepare time: %.6f" % (time.time() - start_time, ))
예제 #4
0
def post_process(sid):
	try:
		db.c.start_transaction()
		start_time = time.time()
		playlist.prepare_cooldown_algorithm(sid)
		rainwave.playlist_objects.album.clear_updated_albums(sid)
		log.debug("post", "Playlist prepare time: %.6f" % (time.time() - start_time,))

		start_time = time.time()
		current[sid].finish()
		log.debug("post", "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("post", "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("post", "History management: %.6f" % (time.time() - start_time,))

		start_time = time.time()
		current[sid] = upnext[sid].pop(0)
		current[sid].start_event()
		log.debug("advance", "Current management: %.6f" % (time.time() - start_time,))

		start_time = time.time()
		playlist.warm_cooled_songs(sid)
		playlist.warm_cooled_albums(sid)
		log.debug("advance", "Cooldown warming: %.6f" % (time.time() - start_time,))

		start_time = time.time()
		_add_listener_count_record(sid)
		_trim(sid)
		user.trim_listeners(sid)
		cache.update_user_rating_acl(sid, history[sid][0].get_song().id)
		user.unlock_listeners(sid)
		log.debug("advance", "User management and trimming: %.6f" % (time.time() - start_time,))

		start_time = time.time()
		# reduce song blocks has to come first, otherwise it wll reduce blocks generated by _create_elections
		playlist.reduce_song_blocks(sid)
		# update_cache updates both the line and expiry times
		# this is expensive and not necessary to do more than once
		# DO THIS AFTER EVERYTHING ELSE, RIGHT BEFORE NEXT MANAGEMENT, OR PEOPLE'S REQUESTS SLIP THROUGH THE CRACKS
		request.update_line(sid)
		# add to the event list / update start times for events
		manage_next(sid)
		# update expire times AFTER manage_next, so people who aren't in line anymore don't see expiry times
		request.update_expire_times()
		log.debug("advance", "Request and upnext management: %.6f" % (time.time() - start_time,))

		update_memcache(sid)
		sync_to_front.sync_frontend_all(sid)
		db.c.commit()
	except:
		db.c.rollback()
		raise
예제 #5
0
def post_process(sid):
    try:
        db.c.start_transaction()
        start_time = timestamp()
        playlist.prepare_cooldown_algorithm(sid)
        rainwave.playlist_objects.album.clear_updated_albums(sid)
        log.debug("post", "Playlist prepare time: %.6f" % (timestamp() - start_time,))

        start_time = timestamp()
        current[sid].finish()
        for sched_id in db.c.fetch_list(
            "SELECT sched_id FROM r4_schedule WHERE sched_end < %s AND sched_used = FALSE",
            (timestamp(),),
        ):
            t_evt = events.event.BaseProducer.load_producer_by_id(sched_id)
            t_evt.finish()
        log.debug("post", "Current finish time: %.6f" % (timestamp() - start_time,))

        start_time = timestamp()
        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("post", "Last song insertion time: %s" % (timestamp() - start_time,))

        start_time = timestamp()
        history[sid].insert(0, current[sid])
        while len(history[sid]) > 5:
            history[sid].pop()
        log.debug("post", "History management: %.6f" % (timestamp() - start_time,))

        start_time = timestamp()
        current[sid] = upnext[sid].pop(0)
        current[sid].start_event()
        log.debug("advance", "Current management: %.6f" % (timestamp() - start_time,))

        start_time = timestamp()
        playlist.warm_cooled_songs(sid)
        playlist.warm_cooled_albums(sid)
        log.debug("advance", "Cooldown warming: %.6f" % (timestamp() - start_time,))

        start_time = timestamp()
        _trim(sid)
        user.trim_listeners(sid)
        cache.update_user_rating_acl(sid, history[sid][0].get_song().id)
        user.unlock_listeners(sid)
        db.c.update(
            "UPDATE r4_listeners SET listener_voted_entry = NULL WHERE sid = %s", (sid,)
        )
        log.debug(
            "advance",
            "User management and trimming: %.6f" % (timestamp() - start_time,),
        )

        start_time = timestamp()
        # reduce song blocks has to come first, otherwise it wll reduce blocks generated by _create_elections
        playlist.reduce_song_blocks(sid)
        # update_cache updates both the line and expiry times
        # this is expensive and must be done before and after every request is filled
        # DO THIS AFTER EVERYTHING ELSE, RIGHT BEFORE NEXT MANAGEMENT, OR PEOPLE'S REQUESTS SLIP THROUGH THE CRACKS
        request.update_line(sid)
        # add to the event list / update start times for events
        manage_next(sid)
        # update expire times AFTER manage_next, so people who aren't in line anymore don't see expiry times
        request.update_expire_times()
        log.debug(
            "advance",
            "Request and upnext management: %.6f" % (timestamp() - start_time,),
        )

        update_memcache(sid)

        sync_to_front.sync_frontend_all(sid)
        db.c.commit()
    except:
        db.c.rollback()
        raise

    if (
        current[sid]
        and config.has_station(sid, "tunein_partner_key")
        and config.get_station(sid, "tunein_partner_key")
    ):
        ti_song = current[sid].get_song()
        if ti_song:
            ti_title = ti_song.data["title"]
            ti_album = ti_song.albums[0].data["name"]
            ti_artist = ", ".join([a.data["name"] for a in ti_song.artists])

            params = {
                "id": config.get_station(sid, "tunein_id"),
                "title": ti_title,
                "artist": ti_artist,
                "album": ti_album,
            }

            try:
                req = requests.Request(
                    "GET", "http://air.radiotime.com/Playing.ashx", params=params
                )
                p = req.prepare()
                # Must be done here rather than in params because of odd strings TuneIn creates
                p.url += "&partnerId=%s" % config.get_station(sid, "tunein_partner_id")
                p.url += "&partnerKey=%s" % config.get_station(
                    sid, "tunein_partner_key"
                )
                s = requests.Session()
                resp = s.send(p, timeout=3)
                log.debug(
                    "advance", "TuneIn updated (%s): %s" % (resp.status_code, resp.text)
                )
            except Exception as e:
                log.exception("advance", "Could not update TuneIn.", e)
예제 #6
0
def post_process(sid):
    try:
        db.c.start_transaction()
        start_time = timestamp()
        playlist.prepare_cooldown_algorithm(sid)
        rainwave.playlist_objects.album.clear_updated_albums(sid)
        log.debug("post", "Playlist prepare time: %.6f" % (timestamp() - start_time,))

        start_time = timestamp()
        current[sid].finish()
        for sched_id in db.c.fetch_list(
            "SELECT sched_id FROM r4_schedule WHERE sched_end < %s AND sched_used = FALSE", (timestamp(),)
        ):
            t_evt = events.event.BaseProducer.load_producer_by_id(sched_id)
            t_evt.finish()
        log.debug("post", "Current finish time: %.6f" % (timestamp() - start_time,))

        start_time = timestamp()
        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("post", "Last song insertion time: %s" % (timestamp() - start_time,))

        start_time = timestamp()
        history[sid].insert(0, current[sid])
        while len(history[sid]) > 5:
            history[sid].pop()
        log.debug("post", "History management: %.6f" % (timestamp() - start_time,))

        start_time = timestamp()
        current[sid] = upnext[sid].pop(0)
        current[sid].start_event()
        log.debug("advance", "Current management: %.6f" % (timestamp() - start_time,))

        start_time = timestamp()
        playlist.warm_cooled_songs(sid)
        playlist.warm_cooled_albums(sid)
        log.debug("advance", "Cooldown warming: %.6f" % (timestamp() - start_time,))

        start_time = timestamp()
        _add_listener_count_record(sid)
        _trim(sid)
        user.trim_listeners(sid)
        cache.update_user_rating_acl(sid, history[sid][0].get_song().id)
        user.unlock_listeners(sid)
        db.c.update("UPDATE r4_listeners SET listener_voted_entry = NULL WHERE sid = %s", (sid,))
        log.debug("advance", "User management and trimming: %.6f" % (timestamp() - start_time,))

        start_time = timestamp()
        # reduce song blocks has to come first, otherwise it wll reduce blocks generated by _create_elections
        playlist.reduce_song_blocks(sid)
        # update_cache updates both the line and expiry times
        # this is expensive and must be done before and after every request is filled
        # DO THIS AFTER EVERYTHING ELSE, RIGHT BEFORE NEXT MANAGEMENT, OR PEOPLE'S REQUESTS SLIP THROUGH THE CRACKS
        request.update_line(sid)
        # add to the event list / update start times for events
        manage_next(sid)
        # update expire times AFTER manage_next, so people who aren't in line anymore don't see expiry times
        request.update_expire_times()
        log.debug("advance", "Request and upnext management: %.6f" % (timestamp() - start_time,))

        update_memcache(sid)

        sync_to_front.sync_frontend_all(sid)
        db.c.commit()
    except:
        db.c.rollback()
        raise

    if current[sid] and config.has_station(sid, "tunein_partner_key") and config.get_station(sid, "tunein_partner_key"):
        ti_song = current[sid].get_song()
        if ti_song:
            ti_title = ti_song.data["title"]
            ti_album = ti_song.albums[0].data["name"]
            ti_artist = ", ".join([a.data["name"] for a in ti_song.artists])

            params = {
                "id": config.get_station(sid, "tunein_id"),
                "title": ti_title,
                "artist": ti_artist,
                "album": ti_album,
            }

            try:
                req = requests.Request("GET", "http://air.radiotime.com/Playing.ashx", params=params)
                p = req.prepare()
                # Must be done here rather than in params because of odd strings TuneIn creates
                p.url += "&partnerId=%s" % config.get_station(sid, "tunein_partner_id")
                p.url += "&partnerKey=%s" % config.get_station(sid, "tunein_partner_key")
                s = requests.Session()
                resp = s.send(p, timeout=3)
                log.debug("advance", "TuneIn updated (%s): %s" % (resp.status_code, resp.text))
            except Exception as e:
                log.exception("advance", "Could not update TuneIn.", e)