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


Golang OutputRunner.Ticker方法代碼示例

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


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

示例1: Run

func (k *KinesisOutput) Run(or pipeline.OutputRunner, helper pipeline.PluginHelper) error {
	var pack *pipeline.PipelinePack

	if or.Encoder() == nil {
		return fmt.Errorf("Encoder required.")
	}

	// Handle the ticks from the Ticker asyncronously
	go k.HandleTick(or.Ticker())

	// handle packages
	for pack = range or.InChan() {
		k.HandlePackage(or, pack)
	}

	return nil
}
開發者ID:AutoScout24,項目名稱:heka-kinesis-output,代碼行數:17,代碼來源:kinesis_output.go

示例2: Run

func (s *SandboxOutput) Run(or pipeline.OutputRunner, h pipeline.PluginHelper) (err error) {
	var (
		pack      *pipeline.PipelinePack
		retval    int
		inChan    = or.InChan()
		duration  int64
		startTime time.Time
		ok        = true
		ticker    = or.Ticker()
	)

	for ok {
		select {
		case pack, ok = <-inChan:
			if !ok {
				break
			}
			if s.sample {
				startTime = time.Now()
			}
			retval = s.sb.ProcessMessage(pack)
			if s.sample {
				duration = time.Since(startTime).Nanoseconds()
				s.reportLock.Lock()
				s.processMessageDuration += duration
				s.processMessageSamples++
				s.reportLock.Unlock()
			}
			s.sample = 0 == rand.Intn(s.sampleDenominator)
			pack.Recycle()

			if retval == 0 {
				atomic.AddInt64(&s.processMessageCount, 1)
			} else if retval < 0 {
				atomic.AddInt64(&s.processMessageFailures, 1)
				em := s.sb.LastError()
				if len(em) > 0 {
					or.LogError(errors.New(em))
				}
			} else {
				err = fmt.Errorf("FATAL: %s", s.sb.LastError())
				ok = false
			}

		case t := <-ticker:
			startTime = time.Now()
			if retval = s.sb.TimerEvent(t.UnixNano()); retval != 0 {
				err = fmt.Errorf("FATAL: %s", s.sb.LastError())
				ok = false
			}
			duration = time.Since(startTime).Nanoseconds()
			s.reportLock.Lock()
			s.timerEventDuration += duration
			s.timerEventSamples++
			s.reportLock.Unlock()
		}
	}

	s.reportLock.Lock()
	var destroyErr error
	if s.sbc.PreserveData {
		destroyErr = s.sb.Destroy(s.preservationFile)
	} else {
		destroyErr = s.sb.Destroy("")
	}
	if destroyErr != nil {
		err = destroyErr
	}

	s.sb = nil
	s.reportLock.Unlock()
	return
}
開發者ID:orangemi,項目名稱:heka,代碼行數:73,代碼來源:sandbox_output.go

示例3: Run

func (s *SandboxOutput) Run(or pipeline.OutputRunner, h pipeline.PluginHelper) (err error) {
	var (
		pack      *pipeline.PipelinePack
		retval    int
		inChan    = or.InChan()
		duration  int64
		startTime time.Time
		ok        = true
		ticker    = or.Ticker()
	)

	for ok {
		select {
		case pack, ok = <-inChan:
			if !ok {
				break
			}
			if s.sample {
				startTime = time.Now()
			}
			retval = s.sb.ProcessMessage(pack)
			if s.sample {
				duration = time.Since(startTime).Nanoseconds()
				s.reportLock.Lock()
				s.processMessageDuration += duration
				s.processMessageSamples++
				s.reportLock.Unlock()
			}
			s.sample = 0 == rand.Intn(s.sampleDenominator)

			or.UpdateCursor(pack.QueueCursor) // TODO: support retries?
			if retval == 0 {
				atomic.AddInt64(&s.processMessageCount, 1)
				pack.Recycle(nil)
			} else if retval < 0 {
				atomic.AddInt64(&s.processMessageFailures, 1)
				var e error
				em := s.sb.LastError()
				if len(em) > 0 {
					e = errors.New(em)
				}
				pack.Recycle(e)
			} else {
				err = fmt.Errorf("FATAL: %s", s.sb.LastError())
				pack.Recycle(err)
				ok = false
			}

		case t := <-ticker:
			startTime = time.Now()
			if retval = s.sb.TimerEvent(t.UnixNano()); retval != 0 {
				err = fmt.Errorf("FATAL: %s", s.sb.LastError())
				ok = false
			}
			duration = time.Since(startTime).Nanoseconds()
			s.reportLock.Lock()
			s.timerEventDuration += duration
			s.timerEventSamples++
			s.reportLock.Unlock()
		}
	}

	if err == nil && s.sbc.TimerEventOnShutdown {
		if retval = s.sb.TimerEvent(time.Now().UnixNano()); retval != 0 {
			err = fmt.Errorf("FATAL: %s", s.sb.LastError())
		}
	}

	destroyErr := s.destroy()
	if destroyErr != nil {
		if err != nil {
			or.LogError(err)
		}
		err = destroyErr
	}
	return err
}
開發者ID:Nitro,項目名稱:heka,代碼行數:77,代碼來源:sandbox_output.go


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