mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
cfg: move failed_posts to ees, add static_ttl
This commit is contained in:
committed by
Dan Christian Bogos
parent
082c412159
commit
295ddec792
@@ -53,14 +53,14 @@ func callURL(ub *engine.Account, a *engine.Action, _ engine.Actions, _ *engine.F
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
eeCfg := config.NewEventExporterCfg(a.Id, "", a.ExtraParameters, config.CgrConfig().GeneralCfg().FailedPostsDir,
|
||||
eeCfg := config.NewEventExporterCfg(a.Id, "", a.ExtraParameters, config.CgrConfig().EEsCfg().FailedPosts.Dir,
|
||||
config.CgrConfig().GeneralCfg().PosterAttempts, nil)
|
||||
pstr, err := NewHTTPjsonMapEE(eeCfg, config.CgrConfig(), nil, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = ExportWithAttempts(pstr, &HTTPPosterRequest{Body: body, Header: make(http.Header)}, "")
|
||||
if config.CgrConfig().GeneralCfg().FailedPostsDir != utils.MetaNone {
|
||||
if config.CgrConfig().EEsCfg().FailedPosts.Dir != utils.MetaNone {
|
||||
err = nil
|
||||
}
|
||||
return err
|
||||
@@ -73,7 +73,7 @@ func callURLAsync(ub *engine.Account, a *engine.Action, _ engine.Actions, _ *eng
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
eeCfg := config.NewEventExporterCfg(a.Id, "", a.ExtraParameters, config.CgrConfig().GeneralCfg().FailedPostsDir,
|
||||
eeCfg := config.NewEventExporterCfg(a.Id, "", a.ExtraParameters, config.CgrConfig().EEsCfg().FailedPosts.Dir,
|
||||
config.CgrConfig().GeneralCfg().PosterAttempts, nil)
|
||||
pstr, err := NewHTTPjsonMapEE(eeCfg, config.CgrConfig(), nil, nil)
|
||||
if err != nil {
|
||||
@@ -89,14 +89,14 @@ func postEvent(_ *engine.Account, a *engine.Action, _ engine.Actions, _ *engine.
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
eeCfg := config.NewEventExporterCfg(a.Id, "", a.ExtraParameters, config.CgrConfig().GeneralCfg().FailedPostsDir,
|
||||
eeCfg := config.NewEventExporterCfg(a.Id, "", a.ExtraParameters, config.CgrConfig().EEsCfg().FailedPosts.Dir,
|
||||
config.CgrConfig().GeneralCfg().PosterAttempts, nil)
|
||||
pstr, err := NewHTTPjsonMapEE(eeCfg, config.CgrConfig(), nil, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = ExportWithAttempts(pstr, &HTTPPosterRequest{Body: body, Header: make(http.Header)}, "")
|
||||
if config.CgrConfig().GeneralCfg().FailedPostsDir != utils.MetaNone {
|
||||
if config.CgrConfig().EEsCfg().FailedPosts.Dir != utils.MetaNone {
|
||||
err = nil
|
||||
}
|
||||
return err
|
||||
|
||||
@@ -40,8 +40,8 @@ func init() {
|
||||
}
|
||||
|
||||
// SetFailedPostCacheTTL recreates the failed cache
|
||||
func SetFailedPostCacheTTL(ttl time.Duration) {
|
||||
failedPostCache = ltcache.NewCache(-1, ttl, false, false, []func(itmID string, value any){writeFailedPosts})
|
||||
func SetFailedPostCacheTTL(ttl time.Duration, static bool) {
|
||||
failedPostCache = ltcache.NewCache(-1, ttl, static, false, []func(itmID string, value any){writeFailedPosts})
|
||||
}
|
||||
|
||||
func writeFailedPosts(_ string, value any) {
|
||||
|
||||
@@ -46,7 +46,7 @@ func TestWriteFldPosts(t *testing.T) {
|
||||
if err := os.MkdirAll(dir, 0755); err != nil {
|
||||
t.Fatal("Error creating folder: ", dir, err)
|
||||
}
|
||||
config.CgrConfig().GeneralCfg().FailedPostsDir = dir
|
||||
config.CgrConfig().EEsCfg().FailedPosts.Dir = dir
|
||||
writeFailedPosts("itmID", exportEvent)
|
||||
|
||||
if filename, err := filepath.Glob(filepath.Join(dir, "EEs|*.gob")); err != nil {
|
||||
|
||||
@@ -30,7 +30,7 @@ import (
|
||||
|
||||
func TestSetFldPostCacheTTL(t *testing.T) {
|
||||
var1 := failedPostCache
|
||||
SetFailedPostCacheTTL(50 * time.Millisecond)
|
||||
SetFailedPostCacheTTL(50*time.Millisecond, false)
|
||||
var2 := failedPostCache
|
||||
if reflect.DeepEqual(var1, var2) {
|
||||
t.Error("Expecting to be different")
|
||||
@@ -38,7 +38,7 @@ func TestSetFldPostCacheTTL(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestAddFldPost(t *testing.T) {
|
||||
SetFailedPostCacheTTL(5 * time.Second)
|
||||
SetFailedPostCacheTTL(5*time.Second, false)
|
||||
AddFailedPost("", "path1", "format1", "1", &config.EventExporterOpts{
|
||||
AMQP: &config.AMQPOpts{},
|
||||
Els: &config.ElsOpts{},
|
||||
|
||||
@@ -66,7 +66,7 @@ type TestContent struct {
|
||||
}
|
||||
|
||||
func TestHttpJsonPoster(t *testing.T) {
|
||||
SetFailedPostCacheTTL(time.Millisecond)
|
||||
SetFailedPostCacheTTL(time.Millisecond, false)
|
||||
content := &TestContent{Var1: "Val1", Var2: "Val2"}
|
||||
jsn, _ := json.Marshal(content)
|
||||
pstr, err := NewHTTPjsonMapEE(&config.EventExporterCfg{
|
||||
@@ -123,7 +123,7 @@ func TestHttpJsonPoster(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestHttpBytesPoster(t *testing.T) {
|
||||
SetFailedPostCacheTTL(time.Millisecond)
|
||||
SetFailedPostCacheTTL(time.Millisecond, false)
|
||||
content := []byte(`Test
|
||||
Test2
|
||||
`)
|
||||
|
||||
Reference in New Issue
Block a user