本文整理匯總了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
}
示例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
}
示例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
}