mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 10:06:24 +05:00
Remove redundant dir parameter from processFile methods
Applies to both file readers and loader (for loader, the blank statement was used anyway). It's redundant because for file readers, the rdr.dir value was always passed as the parameter when it was already part of the method's object. Parameter had to also be removed from the WatchDir function and the functions it depends on.
This commit is contained in:
committed by
Dan Christian Bogos
parent
85864ccaa3
commit
b9b07dc561
@@ -107,12 +107,12 @@ func (rdr *CSVFileER) Serve() (err error) {
|
||||
}
|
||||
|
||||
// processFile is called for each file in a directory and dispatches erEvents from it
|
||||
func (rdr *CSVFileER) processFile(fPath, fName string) (err error) {
|
||||
func (rdr *CSVFileER) processFile(fName string) (err error) {
|
||||
if cap(rdr.conReqs) != 0 { // 0 goes for no limit
|
||||
processFile := <-rdr.conReqs // Queue here for maxOpenFiles
|
||||
defer func() { rdr.conReqs <- processFile }()
|
||||
}
|
||||
absPath := path.Join(fPath, fName)
|
||||
absPath := path.Join(rdr.dir, fName)
|
||||
utils.Logger.Info(
|
||||
fmt.Sprintf("<%s> parsing <%s>", utils.ERs, absPath))
|
||||
var file *os.File
|
||||
|
||||
@@ -395,7 +395,7 @@ func TestFileCSVProcessEvent(t *testing.T) {
|
||||
cgrCfg: cfg,
|
||||
cfgIdx: 0,
|
||||
fltrS: fltrs,
|
||||
dir: "/tmp/ers/out/",
|
||||
dir: filePath,
|
||||
rdrEvents: make(chan *erEvent, 1),
|
||||
rdrError: make(chan error, 1),
|
||||
rdrExit: make(chan struct{}),
|
||||
@@ -505,7 +505,7 @@ func TestFileCSVProcessEvent(t *testing.T) {
|
||||
}
|
||||
|
||||
fname := "file1.csv"
|
||||
if err := eR.processFile(filePath, fname); err != nil {
|
||||
if err := eR.processFile(fname); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
select {
|
||||
@@ -532,7 +532,7 @@ func TestFileCSVProcessEventError(t *testing.T) {
|
||||
cgrCfg: cfg,
|
||||
cfgIdx: 0,
|
||||
fltrS: fltrs,
|
||||
dir: "/tmp/ers/out/",
|
||||
dir: filePath,
|
||||
rdrEvents: make(chan *erEvent, 1),
|
||||
rdrError: make(chan error, 1),
|
||||
rdrExit: make(chan struct{}),
|
||||
@@ -540,7 +540,7 @@ func TestFileCSVProcessEventError(t *testing.T) {
|
||||
}
|
||||
eR.conReqs <- struct{}{}
|
||||
errExpect := "open /tmp/TestFileCSVProcessEvent/file1.csv: no such file or directory"
|
||||
if err := eR.processFile(filePath, fname); err == nil || err.Error() != errExpect {
|
||||
if err := eR.processFile(fname); err == nil || err.Error() != errExpect {
|
||||
t.Errorf("Expected %v but received %v", errExpect, err)
|
||||
}
|
||||
}
|
||||
@@ -565,7 +565,7 @@ func TestFileCSVProcessEventError2(t *testing.T) {
|
||||
cgrCfg: cfg,
|
||||
cfgIdx: 0,
|
||||
fltrS: fltrs,
|
||||
dir: "/tmp/ers/out/",
|
||||
dir: filePath,
|
||||
rdrEvents: make(chan *erEvent, 1),
|
||||
rdrError: make(chan error, 1),
|
||||
rdrExit: make(chan struct{}),
|
||||
@@ -578,7 +578,7 @@ func TestFileCSVProcessEventError2(t *testing.T) {
|
||||
}
|
||||
|
||||
errExpect := "unsupported type: <>"
|
||||
if err := eR.processFile(filePath, fname); err == nil || err.Error() != errExpect {
|
||||
if err := eR.processFile(fname); err == nil || err.Error() != errExpect {
|
||||
t.Errorf("Expected %v but received %v", errExpect, err)
|
||||
}
|
||||
if err := os.RemoveAll(filePath); err != nil {
|
||||
@@ -609,7 +609,7 @@ func TestFileCSVProcessEventError3(t *testing.T) {
|
||||
cgrCfg: cfg,
|
||||
cfgIdx: 0,
|
||||
fltrS: fltrs,
|
||||
dir: "/tmp/ers/out/",
|
||||
dir: filePath,
|
||||
rdrEvents: make(chan *erEvent, 1),
|
||||
rdrError: make(chan error, 1),
|
||||
rdrExit: make(chan struct{}),
|
||||
@@ -620,14 +620,14 @@ func TestFileCSVProcessEventError3(t *testing.T) {
|
||||
//
|
||||
eR.Config().Filters = []string{"Filter1"}
|
||||
errExpect := "NOT_FOUND:Filter1"
|
||||
if err := eR.processFile(filePath, fname); err == nil || err.Error() != errExpect {
|
||||
if err := eR.processFile(fname); err == nil || err.Error() != errExpect {
|
||||
t.Errorf("Expected %v but received %v", errExpect, err)
|
||||
}
|
||||
|
||||
//
|
||||
eR.Config().Filters = []string{"*exists:~*req..Account:"}
|
||||
errExpect = "Invalid fieldPath [ Account]"
|
||||
if err := eR.processFile(filePath, fname); err == nil || err.Error() != errExpect {
|
||||
if err := eR.processFile(fname); err == nil || err.Error() != errExpect {
|
||||
t.Errorf("Expected %v but received %v", errExpect, err)
|
||||
}
|
||||
if err := os.RemoveAll(filePath); err != nil {
|
||||
|
||||
@@ -115,12 +115,12 @@ func (rdr *FWVFileER) Serve() (err error) {
|
||||
}
|
||||
|
||||
// processFile is called for each file in a directory and dispatches erEvents from it
|
||||
func (rdr *FWVFileER) processFile(fPath, fName string) (err error) {
|
||||
func (rdr *FWVFileER) processFile(fName string) (err error) {
|
||||
if cap(rdr.conReqs) != 0 { // 0 goes for no limit
|
||||
processFile := <-rdr.conReqs // Queue here for maxOpenFiles
|
||||
defer func() { rdr.conReqs <- processFile }()
|
||||
}
|
||||
absPath := path.Join(fPath, fName)
|
||||
absPath := path.Join(rdr.dir, fName)
|
||||
utils.Logger.Info(
|
||||
fmt.Sprintf("<%s> parsing <%s>", utils.ERs, absPath))
|
||||
var file *os.File
|
||||
|
||||
@@ -283,7 +283,7 @@ func TestFileFWVProcessEvent(t *testing.T) {
|
||||
cgrCfg: cfg,
|
||||
cfgIdx: 0,
|
||||
fltrS: fltrs,
|
||||
dir: "/tmp/fwvErs/out",
|
||||
dir: filePath,
|
||||
rdrEvents: make(chan *erEvent, 1),
|
||||
rdrError: make(chan error, 1),
|
||||
rdrExit: make(chan struct{}),
|
||||
@@ -304,7 +304,7 @@ func TestFileFWVProcessEvent(t *testing.T) {
|
||||
},
|
||||
}
|
||||
eR.Config().Fields[0].ComputePath()
|
||||
if err := eR.processFile(filePath, fname); err == nil || err.Error() != errExpect {
|
||||
if err := eR.processFile(fname); err == nil || err.Error() != errExpect {
|
||||
t.Errorf("Expected %v but received %v", errExpect, err)
|
||||
}
|
||||
if err := os.RemoveAll(filePath); err != nil {
|
||||
|
||||
@@ -109,12 +109,12 @@ func (rdr *JSONFileER) Serve() (err error) {
|
||||
}
|
||||
|
||||
// processFile is called for each file in a directory and dispatches erEvents from it
|
||||
func (rdr *JSONFileER) processFile(fPath, fName string) (err error) {
|
||||
func (rdr *JSONFileER) processFile(fName string) (err error) {
|
||||
if cap(rdr.conReqs) != 0 { // 0 goes for no limit
|
||||
processFile := <-rdr.conReqs // Queue here for maxOpenFiles
|
||||
defer func() { rdr.conReqs <- processFile }()
|
||||
}
|
||||
absPath := path.Join(fPath, fName)
|
||||
absPath := path.Join(rdr.dir, fName)
|
||||
utils.Logger.Info(
|
||||
fmt.Sprintf("<%s> parsing <%s>", utils.ERs, absPath))
|
||||
var file *os.File
|
||||
|
||||
@@ -340,7 +340,7 @@ func TestFileJSONProcessEvent(t *testing.T) {
|
||||
cgrCfg: cfg,
|
||||
cfgIdx: 0,
|
||||
fltrS: fltrs,
|
||||
dir: "/tmp/ErsJSON/out/",
|
||||
dir: filePath,
|
||||
rdrEvents: make(chan *erEvent, 1),
|
||||
rdrError: make(chan error, 1),
|
||||
rdrExit: make(chan struct{}),
|
||||
@@ -366,7 +366,7 @@ func TestFileJSONProcessEvent(t *testing.T) {
|
||||
// expEvent := &utils.CGREvent{}
|
||||
eR.conReqs <- struct{}{}
|
||||
fname := "file1.json"
|
||||
if err := eR.processFile(filePath, fname); err != nil {
|
||||
if err := eR.processFile(fname); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
select {
|
||||
@@ -393,7 +393,7 @@ func TestFileJSONProcessEventReadError(t *testing.T) {
|
||||
cgrCfg: cfg,
|
||||
cfgIdx: 0,
|
||||
fltrS: fltrs,
|
||||
dir: "/tmp/ErsJSON/out/",
|
||||
dir: filePath,
|
||||
rdrEvents: make(chan *erEvent, 1),
|
||||
rdrError: make(chan error, 1),
|
||||
rdrExit: make(chan struct{}),
|
||||
@@ -401,7 +401,7 @@ func TestFileJSONProcessEventReadError(t *testing.T) {
|
||||
}
|
||||
eR.conReqs <- struct{}{}
|
||||
errExpect := "open /tmp/TestFileJSONProcessEvent/file2.json: no such file or directory"
|
||||
if err := eR.processFile(filePath, fname); err == nil || err.Error() != errExpect {
|
||||
if err := eR.processFile(fname); err == nil || err.Error() != errExpect {
|
||||
t.Errorf("Expected %v but received %v", errExpect, err)
|
||||
}
|
||||
}
|
||||
@@ -441,7 +441,7 @@ func TestFileJSONProcessEventError2(t *testing.T) {
|
||||
cgrCfg: cfg,
|
||||
cfgIdx: 0,
|
||||
fltrS: fltrs,
|
||||
dir: "/tmp/ErsJSON/out/",
|
||||
dir: filePath,
|
||||
rdrEvents: make(chan *erEvent, 1),
|
||||
rdrError: make(chan error, 1),
|
||||
rdrExit: make(chan struct{}),
|
||||
@@ -454,7 +454,7 @@ func TestFileJSONProcessEventError2(t *testing.T) {
|
||||
}
|
||||
fname := "file1.json"
|
||||
errExpect := "unsupported type: <>"
|
||||
if err := eR.processFile(filePath, fname); err == nil || err.Error() != errExpect {
|
||||
if err := eR.processFile(fname); err == nil || err.Error() != errExpect {
|
||||
t.Errorf("Expected %v but received %v", errExpect, err)
|
||||
}
|
||||
if err := os.RemoveAll(filePath); err != nil {
|
||||
@@ -500,7 +500,7 @@ func TestFileJSONProcessEventError3(t *testing.T) {
|
||||
cgrCfg: cfg,
|
||||
cfgIdx: 0,
|
||||
fltrS: fltrs,
|
||||
dir: "/tmp/ErsJSON/out/",
|
||||
dir: filePath,
|
||||
rdrEvents: make(chan *erEvent, 1),
|
||||
rdrError: make(chan error, 1),
|
||||
rdrExit: make(chan struct{}),
|
||||
@@ -512,13 +512,13 @@ func TestFileJSONProcessEventError3(t *testing.T) {
|
||||
//
|
||||
eR.Config().Filters = []string{"Filter1"}
|
||||
errExpect := "NOT_FOUND:Filter1"
|
||||
if err := eR.processFile(filePath, fname); err == nil || err.Error() != errExpect {
|
||||
if err := eR.processFile(fname); err == nil || err.Error() != errExpect {
|
||||
t.Errorf("Expected %v but received %v", errExpect, err)
|
||||
}
|
||||
|
||||
//
|
||||
eR.Config().Filters = []string{"*exists:~*req..Account:"}
|
||||
if err := eR.processFile(filePath, fname); err != nil {
|
||||
if err := eR.processFile(fname); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if err := os.RemoveAll(filePath); err != nil {
|
||||
|
||||
@@ -127,12 +127,12 @@ func (rdr *XMLFileER) Serve() (err error) {
|
||||
*/
|
||||
|
||||
// processFile is called for each file in a directory and dispatches erEvents from it
|
||||
func (rdr *XMLFileER) processFile(fPath, fName string) error {
|
||||
func (rdr *XMLFileER) processFile(fName string) error {
|
||||
if cap(rdr.conReqs) != 0 { // 0 goes for no limit
|
||||
processFile := <-rdr.conReqs // Queue here for maxOpenFiles
|
||||
defer func() { rdr.conReqs <- processFile }()
|
||||
}
|
||||
absPath := path.Join(fPath, fName)
|
||||
absPath := path.Join(rdr.dir, fName)
|
||||
utils.Logger.Info(
|
||||
fmt.Sprintf("<%s> parsing <%s>", utils.ERs, absPath))
|
||||
file, err := os.Open(absPath)
|
||||
|
||||
@@ -402,7 +402,7 @@ func TestFileXMLProcessEvent(t *testing.T) {
|
||||
cgrCfg: cfg,
|
||||
cfgIdx: 0,
|
||||
fltrS: fltrs,
|
||||
dir: "/tmp/xmlErs/out",
|
||||
dir: filePath,
|
||||
rdrEvents: make(chan *erEvent, 1),
|
||||
rdrError: make(chan error, 1),
|
||||
rdrExit: make(chan struct{}),
|
||||
@@ -424,7 +424,7 @@ func TestFileXMLProcessEvent(t *testing.T) {
|
||||
|
||||
eR.conReqs <- struct{}{}
|
||||
fileName := "file1.xml"
|
||||
if err := eR.processFile(filePath, fileName); err != nil {
|
||||
if err := eR.processFile(fileName); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
expEvent := &utils.CGREvent{
|
||||
@@ -458,7 +458,7 @@ func TestFileXMLProcessEventError1(t *testing.T) {
|
||||
cgrCfg: cfg,
|
||||
cfgIdx: 0,
|
||||
fltrS: fltrs,
|
||||
dir: "/tmp/xmlErs/out/",
|
||||
dir: filePath,
|
||||
rdrEvents: make(chan *erEvent, 1),
|
||||
rdrError: make(chan error, 1),
|
||||
rdrExit: make(chan struct{}),
|
||||
@@ -466,7 +466,7 @@ func TestFileXMLProcessEventError1(t *testing.T) {
|
||||
}
|
||||
eR.conReqs <- struct{}{}
|
||||
errExpect := "open /tmp/TestFileXMLProcessEvent/file1.xml: no such file or directory"
|
||||
if err := eR.processFile(filePath, fname); err == nil || err.Error() != errExpect {
|
||||
if err := eR.processFile(fname); err == nil || err.Error() != errExpect {
|
||||
t.Errorf("Expected %v but received %v", errExpect, err)
|
||||
}
|
||||
}
|
||||
@@ -504,7 +504,7 @@ func TestFileXMLProcessEVentError2(t *testing.T) {
|
||||
cgrCfg: cfg,
|
||||
cfgIdx: 0,
|
||||
fltrS: fltrs,
|
||||
dir: "/tmp/xmlErs/out/",
|
||||
dir: filePath,
|
||||
rdrEvents: make(chan *erEvent, 1),
|
||||
rdrError: make(chan error, 1),
|
||||
rdrExit: make(chan struct{}),
|
||||
@@ -520,14 +520,14 @@ func TestFileXMLProcessEVentError2(t *testing.T) {
|
||||
//
|
||||
eR.Config().Filters = []string{"Filter1"}
|
||||
errExpect := "NOT_FOUND:Filter1"
|
||||
if err := eR.processFile(filePath, fname); err == nil || err.Error() != errExpect {
|
||||
if err := eR.processFile(fname); err == nil || err.Error() != errExpect {
|
||||
t.Errorf("Expected %v but received %v", errExpect, err)
|
||||
}
|
||||
|
||||
//
|
||||
eR.Config().Filters = []string{"*exists:~*req..Account:"}
|
||||
errExpect = "rename /tmp/TestFileXMLProcessEvent/file1.xml /var/spool/cgrates/ers/out/file1.xml: no such file or directory"
|
||||
if err := eR.processFile(filePath, fname); err == nil || err.Error() != errExpect {
|
||||
if err := eR.processFile(fname); err == nil || err.Error() != errExpect {
|
||||
t.Errorf("Expected %v but received %v", errExpect, err)
|
||||
}
|
||||
if err := os.RemoveAll(filePath); err != nil {
|
||||
@@ -554,7 +554,7 @@ func TestFileXMLProcessEventParseError(t *testing.T) {
|
||||
cgrCfg: cfg,
|
||||
cfgIdx: 0,
|
||||
fltrS: fltrs,
|
||||
dir: "/tmp/xmlErs/out",
|
||||
dir: filePath,
|
||||
rdrEvents: make(chan *erEvent, 1),
|
||||
rdrError: make(chan error, 1),
|
||||
rdrExit: make(chan struct{}),
|
||||
@@ -564,7 +564,7 @@ func TestFileXMLProcessEventParseError(t *testing.T) {
|
||||
|
||||
fileName := "file1.xml"
|
||||
errExpect := "XML syntax error on line 2: unexpected EOF"
|
||||
if err := eR.processFile(filePath, fileName); err == nil || err.Error() != errExpect {
|
||||
if err := eR.processFile(fileName); err == nil || err.Error() != errExpect {
|
||||
t.Errorf("Expected %v but received %v", errExpect, err)
|
||||
}
|
||||
if err := os.RemoveAll(filePath); err != nil {
|
||||
|
||||
@@ -108,7 +108,7 @@ func mergePartialEvents(cgrEvs []*utils.CGREvent, cfg *config.EventReaderCfg, fl
|
||||
|
||||
// processReaderDir finds all entries within dirPath, filters only the ones whose name
|
||||
// ends with the specified suffix and executes function f on them.
|
||||
func processReaderDir(dirPath, suffix string, f func(dir, fn string) error) {
|
||||
func processReaderDir(dirPath, suffix string, f func(fn string) error) {
|
||||
filesInDir, err := os.ReadDir(dirPath)
|
||||
if err != nil {
|
||||
utils.Logger.Notice(fmt.Sprintf(
|
||||
@@ -122,7 +122,7 @@ func processReaderDir(dirPath, suffix string, f func(dir, fn string) error) {
|
||||
continue // used in order to filter the files from directory
|
||||
}
|
||||
go func(fileName string) {
|
||||
if err := f(dirPath, fileName); err != nil {
|
||||
if err := f(fileName); err != nil {
|
||||
utils.Logger.Warning(fmt.Sprintf(
|
||||
"<%s> processing file %s, error: %v",
|
||||
utils.ERs, fileName, err))
|
||||
|
||||
Reference in New Issue
Block a user