Add ERs apis to apier package

Now the ErSv1 object methods are registered instead when
starting the ERs service.
This commit is contained in:
ionutboangiu
2024-04-02 20:03:34 +03:00
committed by Dan Christian Bogos
parent 5116a23f5b
commit 0626b050c1
2 changed files with 52 additions and 7 deletions

49
apier/v1/ers.go Normal file
View File

@@ -0,0 +1,49 @@
/*
Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
Copyright (C) ITsysCOM GmbH
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package v1
import (
"github.com/cgrates/birpc/context"
"github.com/cgrates/cgrates/ers"
"github.com/cgrates/cgrates/utils"
)
func NewErSv1(erS *ers.ERService) *ErSv1 {
return &ErSv1{erS: erS}
}
type ErSv1 struct {
erS *ers.ERService
}
func (eeSv1 *ErSv1) Ping(ctx *context.Context, ign *utils.CGREvent, reply *string) error {
*reply = utils.Pong
return nil
}
// V1RunReader processes files in the configured directory for the given reader. This function handles files
// based on the reader's type and configuration. Only available for readers that are not processing files
// automatically (RunDelay should equal 0).
//
// Note: This API is not safe to call concurrently for the same reader. Ensure the current files finish being
// processed before calling again.
func (eeSv1 *ErSv1) RunReader(ctx *context.Context, args utils.StringWithAPIOpts,
reply *string) error {
return eeSv1.erS.V1RunReader(ctx, args, reply)
}

View File

@@ -20,10 +20,10 @@ package services
import (
"fmt"
"strings"
"sync"
"github.com/cgrates/birpc"
v1 "github.com/cgrates/cgrates/apier/v1"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/cores"
"github.com/cgrates/cgrates/engine"
@@ -94,15 +94,11 @@ func (erS *EventReaderService) Start() (err error) {
erS.ers = ers.NewERService(erS.cfg, filterS, erS.connMgr)
go erS.listenAndServe(erS.ers, erS.stopChan, erS.rldChan)
// Register ERs methods whose names start with "V1" under the "ErSv1" object name.
srv, err := birpc.NewServiceWithMethodsRename(erS.ers, utils.ErS, true, func(oldFn string) (newFn string) {
return strings.TrimPrefix(oldFn, "V1")
})
// Register ERsV1 methods.
srv, err := birpc.NewService(v1.NewErSv1(erS.ers), "", false)
if err != nil {
return err
}
engine.RegisterPingMethod(srv.Methods)
if !erS.cfg.DispatcherSCfg().Enabled {
erS.server.RpcRegister(srv)
}