Exemple #1
0
    def get(instance_type):
        nowtime = datetime.datetime.now(pytz.utc)
        cached = None

        if instance_type in SpotPriceCache.CACHE:
            cached = SpotPriceCache.CACHE[instance_type]
            if (cached['time'] - nowtime).total_seconds() < SpotPriceCache.SPOT_PRICE_REFETCH_SECS:
                cached = None

        if cached is None:
            newprices = Cluster.get_spot_price(instance_type)
            cached = {
                'time': nowtime,
                'prices': newprices
            }
            SpotPriceCache.CACHE[instance_type] = cached

        return cached['prices']