From 9376889b106983ff6b1824453bdc2323ce424a9f Mon Sep 17 00:00:00 2001 From: TeoV Date: Wed, 5 Feb 2020 16:37:22 +0200 Subject: [PATCH] Parse RunDelay from EventReader with ParseDurationWithNanosecs fixes #1897 --- config/config_defaults.go | 2 +- config/config_json_test.go | 2 +- config/erscfg.go | 4 +++- config/erscfg_test.go | 4 ++-- config/libconfig_json.go | 2 +- data/conf/samples/ers_example/cgrates.json | 2 +- data/conf/samples/ers_internal/cgrates.json | 22 +++++++++---------- data/conf/samples/ers_mongo/cgrates.json | 22 +++++++++---------- data/conf/samples/ers_mysql/cgrates.json | 22 +++++++++---------- data/conf/samples/ers_postgres/cgrates.json | 22 +++++++++---------- .../ers_reload/first_reload/cgrates.json | 4 ++-- .../samples/ers_reload/internal/cgrates.json | 2 +- .../ers_reload/second_reload/cgrates.json | 12 +++++----- docs/ers.rst | 2 +- ers/kafka_it_test.go | 2 +- ers/sql_it_test.go | 2 +- 16 files changed, 65 insertions(+), 63 deletions(-) diff --git a/config/config_defaults.go b/config/config_defaults.go index 0d9660417..47294ca72 100755 --- a/config/config_defaults.go +++ b/config/config_defaults.go @@ -308,7 +308,7 @@ const CGRATES_CFG_JSON = ` "id": "*default", // identifier of the EventReader profile "type": "*file_csv", // reader type <*file_csv> "field_separator": ",", // separator used in case of csv files - "run_delay": 0, // sleep interval in seconds between consecutive runs, -1 to use automation via inotify or 0 to disable running all together + "run_delay": "0", // sleep interval in seconds between consecutive runs, -1 to use automation via inotify or 0 to disable running all together "concurrent_requests": 1024, // maximum simultaneous requests/files to process, 0 for unlimited "source_path": "/var/spool/cgrates/cdrc/in", // read data from this path "processed_path": "/var/spool/cgrates/cdrc/out", // move processed data here diff --git a/config/config_json_test.go b/config/config_json_test.go index 1ce43aef4..56d612398 100755 --- a/config/config_json_test.go +++ b/config/config_json_test.go @@ -1674,7 +1674,7 @@ func TestDfEventReaderCfg(t *testing.T) { Id: utils.StringPointer(utils.MetaDefault), Type: utils.StringPointer(utils.MetaFileCSV), Field_separator: utils.StringPointer(","), - Run_delay: utils.IntPointer(0), + Run_delay: utils.StringPointer("0"), Concurrent_requests: utils.IntPointer(1024), Source_path: utils.StringPointer("/var/spool/cgrates/cdrc/in"), Processed_path: utils.StringPointer("/var/spool/cgrates/cdrc/out"), diff --git a/config/erscfg.go b/config/erscfg.go index e1fdf28be..47f4e1821 100644 --- a/config/erscfg.go +++ b/config/erscfg.go @@ -132,7 +132,9 @@ func (er *EventReaderCfg) loadFromJsonCfg(jsnCfg *EventReaderJsonCfg, sep string er.FieldSep = *jsnCfg.Field_separator } if jsnCfg.Run_delay != nil { - er.RunDelay = time.Duration(*jsnCfg.Run_delay) + if er.RunDelay, err = utils.ParseDurationWithNanosecs(*jsnCfg.Run_delay); err != nil { + return + } } if jsnCfg.Concurrent_requests != nil { er.ConcurrentReqs = *jsnCfg.Concurrent_requests diff --git a/config/erscfg_test.go b/config/erscfg_test.go index e049fc472..1032e2f37 100644 --- a/config/erscfg_test.go +++ b/config/erscfg_test.go @@ -186,7 +186,7 @@ func TestEventReaderLoadFromJSON(t *testing.T) { "readers": [ { "id": "file_reader1", - "run_delay": -1, + "run_delay": "-1", "type": "*file_csv", "source_path": "/tmp/ers/in", "processed_path": "/tmp/ers/out", @@ -211,7 +211,7 @@ func TestEventReaderSanitisation(t *testing.T) { "readers": [ { "id": "file_reader1", - "run_delay": -1, + "run_delay": "-1", "type": "*file_csv", "source_path": "/tmp/ers/in", "processed_path": "/tmp/ers/out", diff --git a/config/libconfig_json.go b/config/libconfig_json.go index 57558e31f..40856da68 100755 --- a/config/libconfig_json.go +++ b/config/libconfig_json.go @@ -169,7 +169,7 @@ type EventReaderJsonCfg struct { Id *string Type *string Field_separator *string - Run_delay *int + Run_delay *string Concurrent_requests *int Source_path *string Processed_path *string diff --git a/data/conf/samples/ers_example/cgrates.json b/data/conf/samples/ers_example/cgrates.json index 49459e52d..0f5ccb76d 100644 --- a/data/conf/samples/ers_example/cgrates.json +++ b/data/conf/samples/ers_example/cgrates.json @@ -70,7 +70,7 @@ "readers": [ { "id": "file_reader1", - "run_delay": -1, + "run_delay": "-1", "type": "*file_csv", "flags": ["*dryrun"], "source_path": "/tmp/ers/in", diff --git a/data/conf/samples/ers_internal/cgrates.json b/data/conf/samples/ers_internal/cgrates.json index 52f8c8a0f..8b6ccbfb8 100644 --- a/data/conf/samples/ers_internal/cgrates.json +++ b/data/conf/samples/ers_internal/cgrates.json @@ -80,7 +80,7 @@ "readers": [ { "id": "file_reader1", - "run_delay": -1, + "run_delay": "-1", "type": "*file_csv", "flags": ["*dryrun"], "source_path": "/tmp/ers/in", @@ -88,7 +88,7 @@ }, { "id": "file_reader2", - "run_delay": -1, + "run_delay": "-1", "field_separator": ";", "type": "*file_csv", "source_path": "/tmp/ers2/in", @@ -113,7 +113,7 @@ }, { "id": "init_session", - "run_delay": -1, + "run_delay": "-1", "field_separator": ",", "type": "*file_csv", "source_path": "/tmp/init_session/in", @@ -135,7 +135,7 @@ }, { "id": "terminate_session", - "run_delay": -1, + "run_delay": "-1", "field_separator": ",", "type": "*file_csv", "source_path": "/tmp/terminate_session/in", @@ -150,7 +150,7 @@ }, { "id": "create_cdr", - "run_delay": -1, + "run_delay": "-1", "field_separator": ",", "type": "*file_csv", "source_path": "/tmp/cdrs/in", @@ -174,7 +174,7 @@ }, { "id": "file_reader_with_filters", - "run_delay": -1, + "run_delay": "-1", "type": "*file_csv", "field_separator": ";", "source_path": "/tmp/ers_with_filters/in", @@ -201,7 +201,7 @@ }, { "id": "XmlDryRun", - "run_delay": -1, + "run_delay": "-1", "type": "*file_xml", "source_path": "/tmp/xmlErs/in", "flags": ["*cdrs","*log"], @@ -222,7 +222,7 @@ }, { "id": "FWV1", - "run_delay": -1, + "run_delay": "-1", "type": "*file_fwv", "source_path": "/tmp/fwvErs/in", "flags": ["*cdrs"], @@ -255,7 +255,7 @@ { "id": "PartialCSV1", "enabled": true, - "run_delay": -1, + "run_delay": "-1", "type": "*partial_csv", "source_path": "/tmp/partErs1/in", "flags": ["*cdrs"], @@ -296,7 +296,7 @@ { "id": "PartialCSV_PostExpiry", "enabled": true, - "run_delay": -1, + "run_delay": "-1", "type": "*partial_csv", "source_path": "/tmp/partErs2/in", "processed_path": "/tmp/partErs2/out", @@ -326,7 +326,7 @@ { "id": "FlatstoreOsips", "enabled": true, - "run_delay": -1, + "run_delay": "-1", "type": "*flatstore", "field_separator": "|", "source_path": "/tmp/flatstoreErs/in", diff --git a/data/conf/samples/ers_mongo/cgrates.json b/data/conf/samples/ers_mongo/cgrates.json index edd3b0dd6..f1441c622 100644 --- a/data/conf/samples/ers_mongo/cgrates.json +++ b/data/conf/samples/ers_mongo/cgrates.json @@ -81,7 +81,7 @@ "readers": [ { "id": "file_reader1", - "run_delay": -1, + "run_delay": "-1", "type": "*file_csv", "flags": ["*dryrun"], "source_path": "/tmp/ers/in", @@ -89,7 +89,7 @@ }, { "id": "file_reader2", - "run_delay": -1, + "run_delay": "-1", "field_separator": ";", "type": "*file_csv", "source_path": "/tmp/ers2/in", @@ -114,7 +114,7 @@ }, { "id": "init_session", - "run_delay": -1, + "run_delay": "-1", "field_separator": ",", "type": "*file_csv", "source_path": "/tmp/init_session/in", @@ -136,7 +136,7 @@ }, { "id": "terminate_session", - "run_delay": -1, + "run_delay": "-1", "field_separator": ",", "type": "*file_csv", "source_path": "/tmp/terminate_session/in", @@ -151,7 +151,7 @@ }, { "id": "create_cdr", - "run_delay": -1, + "run_delay": "-1", "field_separator": ",", "type": "*file_csv", "source_path": "/tmp/cdrs/in", @@ -175,7 +175,7 @@ }, { "id": "file_reader_with_filters", - "run_delay": -1, + "run_delay": "-1", "type": "*file_csv", "field_separator": ";", "source_path": "/tmp/ers_with_filters/in", @@ -202,7 +202,7 @@ }, { "id": "XmlDryRun", - "run_delay": -1, + "run_delay": "-1", "type": "*file_xml", "source_path": "/tmp/xmlErs/in", "flags": ["*cdrs","*log"], @@ -223,7 +223,7 @@ }, { "id": "FWV1", - "run_delay": -1, + "run_delay": "-1", "type": "*file_fwv", "source_path": "/tmp/fwvErs/in", "flags": ["*cdrs"], @@ -256,7 +256,7 @@ { "id": "PartialCSV1", "enabled": true, - "run_delay": -1, + "run_delay": "-1", "type": "*partial_csv", "source_path": "/tmp/partErs1/in", "flags": ["*cdrs"], @@ -297,7 +297,7 @@ { "id": "PartialCSV_PostExpiry", "enabled": true, - "run_delay": -1, + "run_delay": "-1", "type": "*partial_csv", "source_path": "/tmp/partErs2/in", "processed_path": "/tmp/partErs2/out", @@ -327,7 +327,7 @@ { "id": "FlatstoreOsips", "enabled": true, - "run_delay": -1, + "run_delay": "-1", "type": "*flatstore", "field_separator": "|", "source_path": "/tmp/flatstoreErs/in", diff --git a/data/conf/samples/ers_mysql/cgrates.json b/data/conf/samples/ers_mysql/cgrates.json index 3ac57bf7a..fd8297a4b 100644 --- a/data/conf/samples/ers_mysql/cgrates.json +++ b/data/conf/samples/ers_mysql/cgrates.json @@ -78,7 +78,7 @@ "readers": [ { "id": "file_reader1", - "run_delay": -1, + "run_delay": "-1", "type": "*file_csv", "flags": ["*dryrun"], "source_path": "/tmp/ers/in", @@ -86,7 +86,7 @@ }, { "id": "file_reader2", - "run_delay": -1, + "run_delay": "-1", "field_separator": ";", "type": "*file_csv", "source_path": "/tmp/ers2/in", @@ -111,7 +111,7 @@ }, { "id": "init_session", - "run_delay": -1, + "run_delay": "-1", "field_separator": ",", "type": "*file_csv", "source_path": "/tmp/init_session/in", @@ -133,7 +133,7 @@ }, { "id": "terminate_session", - "run_delay": -1, + "run_delay": "-1", "field_separator": ",", "type": "*file_csv", "source_path": "/tmp/terminate_session/in", @@ -148,7 +148,7 @@ }, { "id": "create_cdr", - "run_delay": -1, + "run_delay": "-1", "field_separator": ",", "type": "*file_csv", "source_path": "/tmp/cdrs/in", @@ -172,7 +172,7 @@ }, { "id": "file_reader_with_filters", - "run_delay": -1, + "run_delay": "-1", "type": "*file_csv", "field_separator": ";", "source_path": "/tmp/ers_with_filters/in", @@ -199,7 +199,7 @@ }, { "id": "XmlDryRun", - "run_delay": -1, + "run_delay": "-1", "type": "*file_xml", "source_path": "/tmp/xmlErs/in", "flags": ["*cdrs","*log"], @@ -220,7 +220,7 @@ }, { "id": "FWV1", - "run_delay": -1, + "run_delay": "-1", "type": "*file_fwv", "source_path": "/tmp/fwvErs/in", "flags": ["*cdrs"], @@ -253,7 +253,7 @@ { "id": "PartialCSV1", "enabled": true, - "run_delay": -1, + "run_delay": "-1", "type": "*partial_csv", "source_path": "/tmp/partErs1/in", "flags": ["*cdrs"], @@ -294,7 +294,7 @@ { "id": "PartialCSV_PostExpiry", "enabled": true, - "run_delay": -1, + "run_delay": "-1", "type": "*partial_csv", "source_path": "/tmp/partErs2/in", "processed_path": "/tmp/partErs2/out", @@ -324,7 +324,7 @@ { "id": "FlatstoreOsips", "enabled": true, - "run_delay": -1, + "run_delay": "-1", "type": "*flatstore", "field_separator": "|", "source_path": "/tmp/flatstoreErs/in", diff --git a/data/conf/samples/ers_postgres/cgrates.json b/data/conf/samples/ers_postgres/cgrates.json index 2b0092dcc..1da038be2 100644 --- a/data/conf/samples/ers_postgres/cgrates.json +++ b/data/conf/samples/ers_postgres/cgrates.json @@ -75,7 +75,7 @@ "readers": [ { "id": "file_reader1", - "run_delay": -1, + "run_delay": "-1", "type": "*file_csv", "flags": ["*dryrun"], "source_path": "/tmp/ers/in", @@ -83,7 +83,7 @@ }, { "id": "file_reader2", - "run_delay": -1, + "run_delay": "-1", "field_separator": ";", "type": "*file_csv", "source_path": "/tmp/ers2/in", @@ -108,7 +108,7 @@ }, { "id": "init_session", - "run_delay": -1, + "run_delay": "-1", "field_separator": ",", "type": "*file_csv", "source_path": "/tmp/init_session/in", @@ -130,7 +130,7 @@ }, { "id": "terminate_session", - "run_delay": -1, + "run_delay": "-1", "field_separator": ",", "type": "*file_csv", "source_path": "/tmp/terminate_session/in", @@ -145,7 +145,7 @@ }, { "id": "create_cdr", - "run_delay": -1, + "run_delay": "-1", "field_separator": ",", "type": "*file_csv", "source_path": "/tmp/cdrs/in", @@ -169,7 +169,7 @@ }, { "id": "file_reader_with_filters", - "run_delay": -1, + "run_delay": "-1", "type": "*file_csv", "field_separator": ";", "source_path": "/tmp/ers_with_filters/in", @@ -196,7 +196,7 @@ }, { "id": "XmlDryRun", - "run_delay": -1, + "run_delay": "-1", "type": "*file_xml", "source_path": "/tmp/xmlErs/in", "flags": ["*cdrs","*log"], @@ -217,7 +217,7 @@ }, { "id": "FWV1", - "run_delay": -1, + "run_delay": "-1", "type": "*file_fwv", "source_path": "/tmp/fwvErs/in", "flags": ["*cdrs"], @@ -250,7 +250,7 @@ { "id": "PartialCSV1", "enabled": true, - "run_delay": -1, + "run_delay": "-1", "type": "*partial_csv", "source_path": "/tmp/partErs1/in", "flags": ["*cdrs"], @@ -291,7 +291,7 @@ { "id": "PartialCSV_PostExpiry", "enabled": true, - "run_delay": -1, + "run_delay": "-1", "type": "*partial_csv", "source_path": "/tmp/partErs2/in", "processed_path": "/tmp/partErs2/out", @@ -321,7 +321,7 @@ { "id": "FlatstoreOsips", "enabled": true, - "run_delay": -1, + "run_delay": "-1", "type": "*flatstore", "field_separator": "|", "source_path": "/tmp/flatstoreErs/in", diff --git a/data/conf/samples/ers_reload/first_reload/cgrates.json b/data/conf/samples/ers_reload/first_reload/cgrates.json index 0ff93d6f8..a18b62153 100644 --- a/data/conf/samples/ers_reload/first_reload/cgrates.json +++ b/data/conf/samples/ers_reload/first_reload/cgrates.json @@ -70,7 +70,7 @@ "readers": [ { "id": "file_reader1", - "run_delay": -1, + "run_delay": "-1", "type": "*file_csv", "flags": ["*cdrs","*log"], "source_path": "/tmp/ers/in", @@ -78,7 +78,7 @@ }, { "id": "file_reader2", - "run_delay": -1, + "run_delay": "-1", "field_separator": ";", "type": "*file_csv", "source_path": "/tmp/ers2/in", diff --git a/data/conf/samples/ers_reload/internal/cgrates.json b/data/conf/samples/ers_reload/internal/cgrates.json index 35319bf31..d769b65c6 100644 --- a/data/conf/samples/ers_reload/internal/cgrates.json +++ b/data/conf/samples/ers_reload/internal/cgrates.json @@ -70,7 +70,7 @@ "readers": [ { "id": "file_reader1", - "run_delay": -1, + "run_delay": "-1", "type": "*file_csv", "flags": ["*dryrun"], "source_path": "/tmp/ers/in", diff --git a/data/conf/samples/ers_reload/second_reload/cgrates.json b/data/conf/samples/ers_reload/second_reload/cgrates.json index 5a9500608..aa2178b2d 100644 --- a/data/conf/samples/ers_reload/second_reload/cgrates.json +++ b/data/conf/samples/ers_reload/second_reload/cgrates.json @@ -70,7 +70,7 @@ "readers": [ { "id": "file_reader1", - "run_delay": -1, + "run_delay": "-1", "type": "*file_csv", "flags": ["*dryrun"], "source_path": "/tmp/ers/in", @@ -78,7 +78,7 @@ }, { "id": "file_reader2", - "run_delay": -1, + "run_delay": "-1", "field_separator": ";", "type": "*file_csv", "source_path": "/tmp/ers2/in", @@ -103,7 +103,7 @@ }, { "id": "init_session", - "run_delay": -1, + "run_delay": "-1", "field_separator": ",", "type": "*file_csv", "source_path": "/tmp/init_session/in", @@ -125,7 +125,7 @@ }, { "id": "terminate_session", - "run_delay": -1, + "run_delay": "-1", "field_separator": ",", "type": "*file_csv", "source_path": "/tmp/terminate_session/in", @@ -140,7 +140,7 @@ }, { "id": "create_cdr", - "run_delay": -1, + "run_delay": "-1", "field_separator": ",", "type": "*file_csv", "source_path": "/tmp/cdrs/in", @@ -164,7 +164,7 @@ }, { "id": "file_reader_with_filters", - "run_delay": -1, + "run_delay": "-1", "type": "*file_csv", "flags": ["*dryrun"], "field_separator": ";", diff --git a/docs/ers.rst b/docs/ers.rst index d7fda3509..2ea91f619 100644 --- a/docs/ers.rst +++ b/docs/ers.rst @@ -36,7 +36,7 @@ With explanations in the comments: "readers": [ // list of active readers { "id": "file_reader2", // file_reader2 reader - "run_delay": -1, // reading of events it is triggered outside of ERs + "run_delay": "-1", // reading of events it is triggered outside of ERs "field_separator": ";", // field separator definition "type": "*file_csv", // type of reader, *file_csv can read .csv files "flags": [ // influence processing logic within CGRateS workflow diff --git a/ers/kafka_it_test.go b/ers/kafka_it_test.go index 4401d6aea..67f9b1055 100644 --- a/ers/kafka_it_test.go +++ b/ers/kafka_it_test.go @@ -48,7 +48,7 @@ func TestKafkaER(t *testing.T) { { "id": "kafka", // identifier of the EventReader profile "type": "*kafka_json_map", // reader type <*file_csv> - "run_delay": -1, // sleep interval in seconds between consecutive runs, -1 to use automation via inotify or 0 to disable running all together + "run_delay": "-1", // sleep interval in seconds between consecutive runs, -1 to use automation via inotify or 0 to disable running all together "concurrent_requests": 1024, // maximum simultaneous requests/files to process, 0 for unlimited "source_path": "localhost:9092", // read data from this path // "processed_path": "/var/spool/cgrates/cdrc/out", // move processed data here diff --git a/ers/sql_it_test.go b/ers/sql_it_test.go index 9f1b1a5cd..601d6bdb1 100644 --- a/ers/sql_it_test.go +++ b/ers/sql_it_test.go @@ -77,7 +77,7 @@ func testSQLInitConfig(t *testing.T) { { "id": "mysql", // identifier of the EventReader profile "type": "*sql", // reader type <*file_csv> - "run_delay": 1, // sleep interval in seconds between consecutive runs, -1 to use automation via inotify or 0 to disable running all together + "run_delay": "1", // sleep interval in seconds between consecutive runs, -1 to use automation via inotify or 0 to disable running all together "concurrent_requests": 1024, // maximum simultaneous requests/files to process, 0 for unlimited "source_path": "*mysql://cgrates:CGRateS.org@127.0.0.1:3306?db_name=cgrates2", // read data from this path "processed_path": "db_name=cgrates2&table_name=cdrs2", // move processed data here