當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Tasks.Exited方法代碼示例

本文整理匯總了Golang中github.com/microscaling/microscaling/demand.Tasks.Exited方法的典型用法代碼示例。如果您正苦於以下問題:Golang Tasks.Exited方法的具體用法?Golang Tasks.Exited怎麽用?Golang Tasks.Exited使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/microscaling/microscaling/demand.Tasks的用法示例。


在下文中一共展示了Tasks.Exited方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: main


//.........這裏部分代碼省略.........

	// Let the scheduler know about the task types.
	for _, task := range tasks.Tasks {
		err = s.InitScheduler(task)
		if err != nil {
			log.Errorf("Failed to start task %s: %v", task.Name, err)
			return
		}
	}

	// Check if there are already any of these containers running
	err = s.CountAllTasks(tasks)
	if err != nil {
		log.Errorf("Failed to count containers. %v", err)
	}

	// Set the initial requested counts to match what's running
	for name, task := range tasks.Tasks {
		task.Requested = task.Running
		tasks.Tasks[name] = task
	}

	// Prepare for cleanup when we receive an interrupt
	closedown := make(chan os.Signal, 1)
	signal.Notify(closedown, os.Interrupt)
	signal.Notify(closedown, syscall.SIGTERM)

	// Open a web socket to the server TODO!! This won't always be necessary if we're not sending metrics & calculating demand locally
	ws, err := utils.InitWebSocket(st.microscalingAPI)
	if err != nil {
		log.Errorf("Failed to open web socket: %v", err)
		return
	}

	de, err := getDemandEngine(st, ws)
	if err != nil {
		log.Errorf("Failed to get demand engine: %v", err)
		return
	}

	go de.GetDemand(tasks, demandUpdate)

	// Handle demand updates
	go func() {
		for range demandUpdate {
			err = s.StopStartTasks(tasks)
			if err != nil {
				log.Errorf("Failed to stop / start tasks. %v", err)
			}
		}

		// When the demandUpdate channel is closed, it's time to scale everything down to 0
		cleanup(s, tasks)
	}()

	// Periodically read the current state of tasks
	getMetricsTimeout := time.NewTicker(constGetMetricsTimeout * time.Millisecond)
	go func() {
		for _ = range getMetricsTimeout.C {
			// Find out how many instances of each task are running
			err = s.CountAllTasks(tasks)
			if err != nil {
				log.Errorf("Failed to count containers. %v", err)
			}
		}
	}()

	// Periodically send metrics to any monitors
	monitors := getMonitors(st, ws)
	if len(monitors) > 0 {
		sendMetricsTimeout := time.NewTicker(constSendMetricsTimeout * time.Millisecond)
		go func() {
			for _ = range sendMetricsTimeout.C {
				for _, m := range monitors {
					err = m.SendMetrics(tasks)
					if err != nil {
						log.Errorf("Failed to send metrics. %v", err)
					}
				}
			}
		}()
	}

	// When we're asked to close down, we don't want to handle demand updates any more
	<-closedown
	log.Info("Clean up when ready")
	// Give the scheduler a chance to do any necessary cleanup
	s.Cleanup()
	// The demand engine is responsible for closing the demandUpdate channel so that we stop
	// doing scaling operations
	de.StopDemand(demandUpdate)

	exitWaitTimeout := time.NewTicker(constGetMetricsTimeout * time.Millisecond)
	for _ = range exitWaitTimeout.C {
		if tasks.Exited() {
			log.Info("All finished")
			break
		}
	}
}
開發者ID:microscaling,項目名稱:microscaling,代碼行數:101,代碼來源:main.go


注:本文中的github.com/microscaling/microscaling/demand.Tasks.Exited方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。