本文整理匯總了Golang中github.com/cgrates/cgrates/utils.StoredCdr.MediationRunId方法的典型用法代碼示例。如果您正苦於以下問題:Golang StoredCdr.MediationRunId方法的具體用法?Golang StoredCdr.MediationRunId怎麽用?Golang StoredCdr.MediationRunId使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/cgrates/cgrates/utils.StoredCdr
的用法示例。
在下文中一共展示了StoredCdr.MediationRunId方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: RateCdr
func (self *Mediator) RateCdr(storedCdr *utils.StoredCdr, sendToStats bool) error {
storedCdr.MediationRunId = utils.DEFAULT_RUNID
cdrRuns := []*utils.StoredCdr{storedCdr} // Start with initial storCdr, will add here all to be mediated
attrsDC := utils.AttrDerivedChargers{Tenant: storedCdr.Tenant, Category: storedCdr.Category, Direction: storedCdr.Direction,
Account: storedCdr.Account, Subject: storedCdr.Subject}
var dcs utils.DerivedChargers
if err := self.connector.GetDerivedChargers(attrsDC, &dcs); err != nil {
errText := fmt.Sprintf("Could not get derived charging for cgrid %s, error: %s", storedCdr.CgrId, err.Error())
Logger.Err(errText)
return errors.New(errText)
}
for _, dc := range dcs {
runFilters, _ := utils.ParseRSRFields(dc.RunFilters, utils.INFIELD_SEP)
matchingAllFilters := true
for _, dcRunFilter := range runFilters {
if fltrPass, _ := storedCdr.PassesFieldFilter(dcRunFilter); !fltrPass {
matchingAllFilters = false
break
}
}
if !matchingAllFilters { // Do not process the derived charger further if not all filters were matched
continue
}
dcReqTypeFld, _ := utils.NewRSRField(dc.ReqTypeField)
dcDirFld, _ := utils.NewRSRField(dc.DirectionField)
dcTenantFld, _ := utils.NewRSRField(dc.TenantField)
dcCategoryFld, _ := utils.NewRSRField(dc.CategoryField)
dcAcntFld, _ := utils.NewRSRField(dc.AccountField)
dcSubjFld, _ := utils.NewRSRField(dc.SubjectField)
dcDstFld, _ := utils.NewRSRField(dc.DestinationField)
dcSTimeFld, _ := utils.NewRSRField(dc.SetupTimeField)
dcATimeFld, _ := utils.NewRSRField(dc.AnswerTimeField)
dcDurFld, _ := utils.NewRSRField(dc.UsageField)
forkedCdr, err := storedCdr.ForkCdr(dc.RunId, dcReqTypeFld, dcDirFld, dcTenantFld, dcCategoryFld, dcAcntFld, dcSubjFld, dcDstFld, dcSTimeFld, dcATimeFld, dcDurFld,
[]*utils.RSRField{}, true)
if err != nil { // Errors on fork, cannot calculate further, write that into db for later analysis
self.cdrDb.SetRatedCdr(&utils.StoredCdr{CgrId: storedCdr.CgrId, CdrSource: utils.FORKED_CDR, MediationRunId: dc.RunId, Cost: -1},
err.Error()) // Cannot fork CDR, important just runid and error
continue
}
cdrRuns = append(cdrRuns, forkedCdr)
}
for _, cdr := range cdrRuns {
extraInfo := ""
if err := self.rateCDR(cdr); err != nil {
extraInfo = err.Error()
}
if !self.cgrCfg.MediatorStoreDisable {
if err := self.cdrDb.SetRatedCdr(cdr, extraInfo); err != nil {
Logger.Err(fmt.Sprintf("<Mediator> Could not record cost for cgrid: <%s>, ERROR: <%s>, cost: %f, extraInfo: %s",
cdr.CgrId, err.Error(), cdr.Cost, extraInfo))
}
}
if sendToStats && self.stats != nil { // We send to stats only after saving to db since there are chances we cannot store and then no way to reproduce stats offline
go func(cdr *utils.StoredCdr) { // Pass it by value since the variable will be overwritten by for
if err := self.stats.AppendCDR(cdr, nil); err != nil {
Logger.Err(fmt.Sprintf("Could not append cdr to stats (mediator): %s", err.Error()))
}
}(cdr)
}
}
return nil
}