Threshold.ProcessEvent

This commit is contained in:
DanB
2017-09-29 18:41:58 +02:00
parent 7eb6d9600b
commit b54ac6e3b5
5 changed files with 174 additions and 39 deletions

View File

@@ -41,6 +41,8 @@ import (
"strings"
"sync"
"time"
"github.com/cgrates/rpcclient"
)
func NewCounter(start, limit int64) *Counter {
@@ -779,3 +781,30 @@ type TenantID struct {
func (tID *TenantID) TenantID() string {
return ConcatenatedKey(tID.Tenant, tID.ID)
}
// RPCCall is a generic method calling RPC on a struct instance
// serviceMethod is assumed to be in the form InstanceV1.Method
// where V1Method will become RPC method called on instance
func RPCCall(inst interface{}, serviceMethod string, args interface{}, reply interface{}) error {
methodSplit := strings.Split(serviceMethod, ".")
if len(methodSplit) != 2 {
return rpcclient.ErrUnsupporteServiceMethod
}
method := reflect.ValueOf(inst).MethodByName(methodSplit[0][len(methodSplit[0])-2:] + methodSplit[1])
if !method.IsValid() {
return rpcclient.ErrUnsupporteServiceMethod
}
params := []reflect.Value{reflect.ValueOf(args), reflect.ValueOf(reply)}
ret := method.Call(params)
if len(ret) != 1 {
return ErrServerError
}
if ret[0].Interface() == nil {
return nil
}
err, ok := ret[0].Interface().(error)
if !ok {
return ErrServerError
}
return err
}