Пример #1
0
// cleanup resets demand for all tasks to 0 before we quit
func cleanup(s scheduler.Scheduler, tasks map[string]demand.Task) {
	var err error

	for name, task := range tasks {
		task.Demand = 0
		tasks[name] = task
	}

	log.Printf("Reset tasks to 0 for cleanup")
	err = s.StopStartTasks(tasks)
	if err != nil {
		log.Printf("Failed to cleanup tasks. %v", err)
	}
}
Пример #2
0
// handleDemandChange checks the new demand
func handleDemandChange(input demand.Input, s scheduler.Scheduler, ready chan struct{}, tasks map[string]demand.Task) error {
	var err error = nil
	var demandChanged bool

	demandChanged, err = update(input, tasks)
	if err != nil {
		log.Printf("Failed to get new demand. %v", err)
		return err
	}

	if demandChanged {
		// Ask the scheduler to make the changes
		err = s.StopStartTasks(tasks, ready)
		if err != nil {
			log.Printf("Failed to stop / start tasks. %v", err)
		}
	} else {
		ready <- struct{}{}
	}

	return err
}
Пример #3
0
// handleDemandChange updates to changed demand
func handleDemandChange(td []api.TaskDemand, s scheduler.Scheduler, tasks map[string]demand.Task) (err error) {
	var demandChanged bool = false
	for _, task := range td {
		name := task.App

		if existing_task, ok := tasks[name]; ok {
			if existing_task.Demand != task.DemandCount {
				demandChanged = true
			}
			existing_task.Demand = task.DemandCount
			tasks[name] = existing_task
		}
	}

	if demandChanged {
		// Ask the scheduler to make the changes
		err = s.StopStartTasks(tasks)
		if err != nil {
			log.Printf("Failed to stop / start tasks. %v", err)
		}
	}

	return
}