(spot_prices, writer, dedupe_interval_seconds)
Write spot price data from EC2 to the clusterman metrics client.

    :param spot_prices: iterable of spot price objects from EC2.
    :param writer: co-routine for writing to metrics client.
    :param dedupe_interval_seconds: int. Will write at most one price per interval per market.
Write spot price data from EC2 to the clusterman metrics client.
Write spot price data from EC2 to the clusterman metrics client .
def write_prices_with_dedupe(spot_prices, writer, dedupe_interval_seconds):
    """
    Write spot price data from EC2 to the clusterman metrics client.

    :param spot_prices: iterable of spot price objects from EC2.
    :param writer: co-routine for writing to metrics client.
    :param dedupe_interval_seconds: int. Will write at most one price per interval per market.
    """
    # Prices are ordered by time, descending.
    # We take the price closest to the end of each interval.
    last_interval_written_by_market = {}
    for price in spot_prices:
        price_time = arrow.get(price["Timestamp"])

        # Round timestamp up to the nearest interval
        seconds_to_next_interval = (dedupe_interval_seconds - price_time.timestamp) % dedupe_interval_seconds
        next_interval = price_time.shift(seconds=seconds_to_next_interval)

        market = (price["InstanceType"], price["AvailabilityZone"])
        last_interval_written = last_interval_written_by_market.get(market, None)
        if not last_interval_written or next_interval < last_interval_written:
            last_interval_written_by_market[market] = next_interval
            data = get_data_for_price(price, next_interval)
            writer.send(data)
def write_prices_with_dedupe ( spot_prices , writer , dedupe_interval_seconds ) : # Prices are ordered by time, descending. # We take the price closest to the end of each interval. last_interval_written_by_market = { } for price in spot_prices : price_time = arrow . get ( price [ "Timestamp" ] ) # Round timestamp up to the nearest interval seconds_to_next_interval = ( dedupe_interval_seconds - price_time . timestamp ) % dedupe_interval_seconds next_interval = price_time . shift ( seconds = seconds_to_next_interval ) market = ( price [ "InstanceType" ] , price [ "AvailabilityZone" ] ) last_interval_written = last_interval_written_by_market . get ( market , None ) if not last_interval_written or next_interval < last_interval_written : last_interval_written_by_market [ market ] = next_interval data = get_data_for_price ( price , next_interval ) writer . send ( data )