示例#1
0
// if this should not run, return false
func (tr *TaskRunner) Run(fc *flow.FlowContext) {

	taskGroups := scheduler.GroupTasks(fc)

	tr.Tasks = taskGroups[tr.option.TaskGroupId].Tasks

	if len(tr.Tasks) == 0 {
		log.Println("How can the task group has no tasks!")
		return
	}

	// println("taskGroup", tr.Tasks[0].Name(), "starts")
	// 4. setup task input and output channels
	var wg sync.WaitGroup
	tr.connectInputsAndOutputs(&wg)
	// 6. starts to run the task locally
	for _, task := range tr.Tasks {
		// println("run task", task.Name())
		wg.Add(1)
		go func(task *flow.Task) {
			defer wg.Done()
			task.RunTask()
		}(task)
	}
	// 7. need to close connected output channels
	wg.Wait()
	// println("taskGroup", tr.Tasks[0].Name(), "finishes")
}
示例#2
0
// driver runs on local, controlling all tasks
func (fcd *FlowContextDriver) Run(fc *flow.FlowContext) {

	taskGroups := scheduler.GroupTasks(fc)
	if fcd.option.PlotOutput {
		scheduler.PlotGraph(taskGroups, fc)
		return
	}

	rsyncServer, err := rsync.NewRsyncServer(os.Args[0], fcd.option.RelatedFileNames())
	if err != nil {
		log.Fatalf("Failed to start local server: %v", err)
	}
	rsyncServer.Start()

	sched := scheduler.NewScheduler(
		fcd.option.Leader,
		&scheduler.SchedulerOption{
			DataCenter:     fcd.option.DataCenter,
			Rack:           fcd.option.Rack,
			TaskMemoryMB:   fcd.option.TaskMemoryMB,
			DriverPort:     rsyncServer.Port,
			Module:         fcd.option.Module,
			ExecutableFile: os.Args[0],
		},
	)
	defer fcd.Cleanup(sched, fc, taskGroups)

	go sched.EventLoop()

	// schedule to run the steps
	var wg sync.WaitGroup
	for _, taskGroup := range taskGroups {
		wg.Add(1)
		sched.EventChan <- scheduler.SubmitTaskGroup{
			FlowContext: fc,
			TaskGroup:   taskGroup,
			Bid:         fcd.option.FlowBid / float64(len(taskGroups)),
			WaitGroup:   &wg,
		}
	}
	go sched.Market.FetcherLoop()

	wg.Wait()

	fcd.CloseOutputChannels(fc)

}
示例#3
0
func (fcd *FlowContextDriver) Plot(fc *flow.FlowContext) {
	taskGroups := scheduler.GroupTasks(fc)
	scheduler.PlotGraph(taskGroups, fc)
}