mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
history sync improvements
This commit is contained in:
@@ -37,7 +37,7 @@ const (
|
||||
)
|
||||
|
||||
type FileScribe struct {
|
||||
mu sync.RWMutex
|
||||
mu sync.Mutex
|
||||
fileRoot string
|
||||
gitCommand string
|
||||
destinations records
|
||||
@@ -65,8 +65,6 @@ func NewFileScribe(fileRoot string) (*FileScribe, error) {
|
||||
}
|
||||
|
||||
func (s *FileScribe) Record(rec *Record, out *int) error {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
var fileToSave string
|
||||
switch {
|
||||
case strings.HasPrefix(rec.Key, DESTINATION_PREFIX):
|
||||
@@ -104,6 +102,8 @@ func (s *FileScribe) Record(rec *Record, out *int) error {
|
||||
}
|
||||
|
||||
func (s *FileScribe) gitInit() error {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
if _, err := os.Stat(s.fileRoot); os.IsNotExist(err) {
|
||||
if err := os.MkdirAll(s.fileRoot, os.ModeDir|0755); err != nil {
|
||||
return errors.New("<History> Error creating history folder: " + err.Error())
|
||||
@@ -144,6 +144,8 @@ func (s *FileScribe) gitCommit() error {
|
||||
}
|
||||
|
||||
func (s *FileScribe) load(filename string) error {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
f, err := os.Open(filepath.Join(s.fileRoot, filename))
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -167,6 +169,8 @@ func (s *FileScribe) load(filename string) error {
|
||||
}
|
||||
|
||||
func (s *FileScribe) save(filename string) error {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
f, err := os.Create(filepath.Join(s.fileRoot, filename))
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -28,7 +28,7 @@ import (
|
||||
)
|
||||
|
||||
type MockScribe struct {
|
||||
sync.RWMutex
|
||||
sync.Mutex
|
||||
destinations records
|
||||
ratingProfiles records
|
||||
DestBuf bytes.Buffer
|
||||
@@ -40,8 +40,6 @@ func NewMockScribe() (*MockScribe, error) {
|
||||
}
|
||||
|
||||
func (s *MockScribe) Record(rec *Record, out *int) error {
|
||||
s.Lock()
|
||||
defer s.Unlock()
|
||||
switch {
|
||||
case strings.HasPrefix(rec.Key, DESTINATION_PREFIX):
|
||||
s.destinations = s.destinations.SetOrAdd(&Record{rec.Key[len(DESTINATION_PREFIX):], rec.Object})
|
||||
@@ -55,6 +53,8 @@ func (s *MockScribe) Record(rec *Record, out *int) error {
|
||||
}
|
||||
|
||||
func (s *MockScribe) save(filename string) error {
|
||||
s.Lock()
|
||||
defer s.Unlock()
|
||||
switch filename {
|
||||
case DESTINATIONS_FILE:
|
||||
s.DestBuf.Reset()
|
||||
|
||||
@@ -202,7 +202,7 @@ func (self *Mediator) getCostsFromRater(cdr utils.CDR) (*engine.CallCost, error)
|
||||
// If the mediator calculated a price it will write it to logdb
|
||||
self.storDb.LogCallCost(cdr.GetCgrId(), engine.MEDIATOR_SOURCE, cc)
|
||||
}
|
||||
return cc, nil
|
||||
return cc, err
|
||||
}
|
||||
|
||||
// Parse the files and get cost for every record
|
||||
|
||||
Reference in New Issue
Block a user