'Refill quotas for all active shards.
Args:
last_poll_time: Datetime with the last time the job state was updated.
processing_rate: How many items to process per second overall.
active_shard_states: All active shard states, list of ShardState.'

def refill_quotas(self, last_poll_time, processing_rate, active_shard_states):

    if (not active_shard_states):
        return
    quota_manager = quota.QuotaManager(memcache.Client())
    current_time = int(self._time())
    last_poll_time = time.mktime(last_poll_time.timetuple())
    total_quota_refill = (processing_rate * max(0, (current_time - last_poll_time)))
    quota_refill = int(math.ceil(((1.0 * total_quota_refill) / len(active_shard_states))))
    if (not quota_refill):
        return
    for shard_state in active_shard_states:
        quota_manager.put(shard_state.shard_id, quota_refill)
