本文整理匯總了Golang中github.com/eliothedeman/bangarang/event.Event.SetState方法的典型用法代碼示例。如果您正苦於以下問題:Golang Event.SetState方法的具體用法?Golang Event.SetState怎麽用?Golang Event.SetState使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/eliothedeman/bangarang/event.Event
的用法示例。
在下文中一共展示了Event.SetState方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: processEvent
// Run the given event though the pipeline
func (p *Pipeline) processEvent(e *event.Event) {
// update to current state
e.SetState(event.StatePipeline)
// track stas for this event
p.tracker.TrackEvent(e)
// process this event on every policy
var pol *escalation.Policy
for _, pol = range p.policies {
pol.PassEvent(e)
}
}
示例2: start
// start the policy listening for events
func (p *Policy) start() {
go func() {
var e *event.Event
for {
select {
case toResolve := <-p.resolve:
var c *Condition
// fetch the condition that created this incident
if toResolve.Status == event.CRITICAL {
c = p.Crit
} else if toResolve.Status == event.WARNING {
c = p.Warn
}
if c != nil {
t := c.getTracker(&toResolve.Event)
t.refresh()
}
case <-p.stop:
logrus.Info("Stopping policy", p.Name)
// cleanup the policy. Sometimes they hangaround.
p.clean()
// stop this policy from being stopped again
p.stop = nil
// catch resolve's that could be sent to this policy
res := p.resolve
p.resolve = nil
go func() {
for {
select {
case <-res:
logrus.Info("Attempted to resolve an incident on a policy that no longer exists")
case <-time.After(1 * time.Minute):
return
}
}
}()
return
case e = <-p.in:
e.SetState(event.StatePolicy)
// process the event if it matches the policy
if p.Matches(e) {
// check critical
if shouldAlert, status := p.ActionCrit(e); shouldAlert {
incident := event.NewIncident(p.Name, status, e)
incident.SetResolve(p.resolve)
// send send it off to the next hop
p.next.PassIncident(incident)
// check warning
} else if shouldAlert, status := p.ActionWarn(e); shouldAlert {
incident := event.NewIncident(p.Name, status, e)
incident.SetResolve(p.resolve)
// send it off to the next hop
p.next.PassIncident(incident)
} else {
e.SetState(event.StateComplete)
}
}
}
}
}()
}