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


Golang WorkerContainer.QC方法代碼示例

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


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

示例1: ExampleWorkerContainer_safe

// the goroutine cycle absolutely safe, no panic no error to quit.
func ExampleWorkerContainer_safe() {
	var wc core.WorkerContainer
	wc.GFork("myservice", func(wc core.WorkerContainer) {
		defer func() {
			if r := recover(); r != nil {
				// log the r and ignore.
				return
			}
		}()

		for {
			select {
			case <-time.After(3 * time.Second):
				// select other channel, do something cycle to get error.
				if err := error(nil); err != nil {
					// recoverable error, log it only and continue or return.
					continue
				}
			case <-wc.QC():
				// when got a quit signal, break the loop.
				// and must notify the container again for other workers
				// in container to quit.
				wc.Quit()
				return
			}
		}
	})
}
開發者ID:QilongZhang,項目名稱:go-oryx,代碼行數:29,代碼來源:example_test.go

示例2: discoveryCycle

func (h *Heartbeat) discoveryCycle(w core.WorkerContainer) {
	interval := time.Duration(0)
	for {
		select {
		case <-w.QC():
			w.Quit()
			return
		case <-time.After(interval):
			core.Info.Println("start to discovery network every", interval)

			if err := h.discovery(); err != nil {
				core.Warn.Println("heartbeat discovery failed, err is", err)
			} else {
				if len(h.ips) <= 0 {
					interval = discoveryEmptyInterval
					continue
				}
				core.Trace.Println("local ip is", h.ips, "exported", h.exportIp)
				interval = discoveryRefreshInterval
			}
		}
	}

	return
}
開發者ID:QilongZhang,項目名稱:go-oryx,代碼行數:25,代碼來源:heartbeat.go

示例3: Run

func (s *Server) Run() (err error) {
	func() {
		s.lock.Lock()
		defer s.lock.Unlock()

		if s.closed != StateReady {
			panic("server invalid state.")
		}
		s.closed = StateRunning
	}()

	// when terminated, notify the chan.
	defer func() {
		select {
		case s.closing <- true:
		default:
		}
	}()

	core.Info.Println("server cycle running")

	// run server, apply settings.
	s.applyMultipleProcesses(core.Conf.Workers)

	var wc core.WorkerContainer = s
	for {
		var gcc <-chan time.Time = nil
		if core.Conf.Go.GcInterval > 0 {
			gcc = time.After(time.Second * time.Duration(core.Conf.Go.GcInterval))
		}

		select {
		case signal := <-s.sigs:
			core.Trace.Println("got signal", signal)
			switch signal {
			case os.Interrupt, syscall.SIGTERM:
				// SIGINT, SIGTERM
				wc.Quit()
			}
		case <-wc.QC():
			wc.Quit()

			// wait for all goroutines quit.
			s.wg.Wait()
			core.Warn.Println("server cycle ok")
			return
		case <-gcc:
			runtime.GC()
			core.Info.Println("go runtime gc every", core.Conf.Go.GcInterval, "seconds")
		}
	}

	return
}
開發者ID:QilongZhang,項目名稱:go-oryx,代碼行數:54,代碼來源:server.go

示例4: ExampleWorkerContainer_fatal

// the goroutine cycle notify container to quit when error.
func ExampleWorkerContainer_fatal() {
	var wc core.WorkerContainer
	wc.GFork("myservice", func(wc core.WorkerContainer) {
		for {
			select {
			case <-time.After(3 * time.Second):
				// select other channel, do something cycle to get error.
				if err := error(nil); err != nil {
					// when got none-recoverable error, notify container to quit.
					wc.Quit()
					return
				}
			case <-wc.QC():
				// when got a quit signal, break the loop.
				// and must notify the container again for other workers
				// in container to quit.
				wc.Quit()
				return
			}
		}
	})
}
開發者ID:QilongZhang,項目名稱:go-oryx,代碼行數:23,代碼來源:example_test.go

示例5: beatCycle

func (h *Heartbeat) beatCycle(w core.WorkerContainer) {
	for {
		c := &core.Conf.Heartbeat

		select {
		case <-w.QC():
			w.Quit()
			return
		case <-time.After(time.Millisecond * time.Duration(1000*c.Interval)):
			if !c.Enabled {
				continue
			}

			core.Info.Println("start to heartbeat every", c.Interval)

			if err := h.beat(); err != nil {
				core.Warn.Println("heartbeat to", c.Url, "every", c.Interval, "failed, err is", err)
			} else {
				core.Info.Println("heartbeat to", c.Url, "every", c.Interval)
			}
		}
	}
}
開發者ID:QilongZhang,項目名稱:go-oryx,代碼行數:23,代碼來源:heartbeat.go


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