Пример #1
0
func (rep *Representative) Claim(instance instance.Instance) {
	rep.lock.Lock()
	defer rep.lock.Unlock()

	_, ok := rep.instances[instance.InstanceGuid]
	if !ok {
		panic("wat?")
	}

	instance.Tentative = false
	rep.instances[instance.InstanceGuid] = instance
}
Пример #2
0
func (rep *Representative) ReserveAndRecastVote(instance instance.Instance) (float64, error) {
	rep.lock.Lock()
	defer rep.lock.Unlock()

	if !rep.hasRoomFor(instance) {
		return 0, InsufficientResources
	}

	score := rep.score(instance) //recompute score *first*
	instance.Tentative = true
	rep.instances[instance.InstanceGuid] = instance //*then* make reservation

	return score, nil
}