MSP-5093 remove global varibale

This commit is contained in:
komissarovyv committed 2025-03-26 11:28:43 +03:00
1 parent 055921d711
commit 46fc51275e
8 files changed
+23 -19

No files matched your search

+2 -1
View File
@@ -2,6 +2,7 @@ package assembly
import (
"context"
"time"
"github.com/pkg/errors"
"github.com/txix-open/isp-kit/app"
@@ -70,7 +71,7 @@ func (a *Assembly) ReceiveConfig(ctx context.Context, remoteConfig []byte) error
return nil, errors.WithMessage(err, "new repository")
}
return repo, nil
}, newCfg)
}, newCfg, time.Minute)
a.server.Upgrade(config.Handler)
+8 -7
View File
@@ -22,10 +22,6 @@ import (
"msp-admin-service/transaction"
)
var (
JobPollInterval = 1 * time.Minute //nolint:gochecknoglobals
)
type DB interface {
db.DB
db.Transactional
@@ -51,7 +47,12 @@ type Config struct {
}
//nolint:funlen
func (l Locator) Config(ctx context.Context, ldapRepoSupplier ldap.RepoSupplier, cfg conf.Remote) Config {
func (l Locator) Config(
ctx context.Context,
ldapRepoSupplier ldap.RepoSupplier,
cfg conf.Remote,
jobPollInterval time.Duration,
) Config {
sudirRepo := repository.NewSudir(l.httpCli, cfg.SudirAuth)
roleRepo := repository.NewRole(l.db)
userRepo := repository.NewUser(l.db)
@@ -129,12 +130,12 @@ func (l Locator) Config(ctx context.Context, ldapRepoSupplier ldap.RepoSupplier,
BgJobCfg: []bgjobx.WorkerConfig{{
Queue: delete_old_audit_worker.QueueName,
Concurrency: 1,
PollInterval: JobPollInterval,
PollInterval: jobPollInterval,
Handle: deleteOldAuditWorker,
}, {
Queue: inactive_worker.QueueName,
Concurrency: 1,
PollInterval: JobPollInterval,
PollInterval: jobPollInterval,
Handle: inactiveBlocker,
}},
}
+2 -1
View File
@@ -3,6 +3,7 @@ package tests_test
import (
"context"
"testing"
"time"
"github.com/stretchr/testify/suite"
"github.com/txix-open/isp-kit/dbx"
@@ -65,7 +66,7 @@ func (t *AuditSuite) SetupTest() {
},
}
cfg := assembly.NewLocator(testInstance.Logger(), httpcli.New(), t.db).
Config(context.Background(), emptyLdap, remote)
Config(context.Background(), emptyLdap, remote, time.Minute)
server, apiCli := grpct.TestServer(testInstance, cfg.Handler)
t.grpcCli = apiCli
+1 -1
View File
@@ -65,7 +65,7 @@ func (s *AuthTestSuite) SetupTest() {
},
}
cfg := assembly.NewLocator(testInstance.Logger(), s.httpCli, s.db).
Config(context.Background(), emptyLdap, remote)
Config(context.Background(), emptyLdap, remote, time.Minute)
server, apiCli := grpct.TestServer(testInstance, cfg.Handler)
s.grpcCli = apiCli
+2 -1
View File
@@ -3,6 +3,7 @@ package tests_test
import (
"context"
"testing"
"time"
"github.com/stretchr/testify/suite"
"github.com/txix-open/isp-kit/dbx"
@@ -39,7 +40,7 @@ func (s *CustomizationTestSuite) SetupTest() {
ExpireSec: 0,
}
cfg := assembly.NewLocator(testInstance.Logger(), nil, s.db).
Config(context.Background(), emptyLdap, remote)
Config(context.Background(), emptyLdap, remote, time.Minute)
server, apiCli := grpct.TestServer(testInstance, cfg.Handler)
s.grpcCli = apiCli
+6 -6
View File
@@ -1,6 +1,7 @@
package tests_test
import (
"msp-admin-service/service/inactive_worker"
"testing"
"time"
@@ -12,7 +13,6 @@ import (
"msp-admin-service/conf"
"msp-admin-service/entity"
"msp-admin-service/repository"
"msp-admin-service/service/inactive_worker"
)
func TestInactiveWorker(t *testing.T) {
@@ -42,14 +42,14 @@ func TestInactiveWorker(t *testing.T) {
Config(t.Context(), emptyLdap, conf.Remote{
BlockInactiveWorker: conf.BlockInactiveWorker{
DaysThreshold: 1,
RunIntervalInMinutes: 60,
RunIntervalInMinutes: 1,
},
})
}, 500*time.Millisecond)
bgjobCli := bgjobx.NewClient(db, test.Logger())
assembly.JobPollInterval = 300 * time.Millisecond
err := bgjobCli.Upgrade(t.Context(), config.BgJobCfg)
err := inactive_worker.EnqueueSeedJob(t.Context(), bgjobCli)
require.NoError(err)
err = inactive_worker.EnqueueSeedJob(t.Context(), bgjobCli)
err = bgjobCli.Upgrade(t.Context(), config.BgJobCfg)
require.NoError(err)
time.Sleep(5 * time.Second)
+1 -1
View File
@@ -40,7 +40,7 @@ func (s *SecureSuite) SetupTest() {
ExpireSec: 3600,
}
cfg := assembly.NewLocator(s.test.Logger(), httpCli, s.db).
Config(context.Background(), emptyLdap, remote)
Config(context.Background(), emptyLdap, remote, time.Minute)
server, apiCli := grpct.TestServer(s.test, cfg.Handler)
s.test.T().Cleanup(func() {
+1 -1
View File
@@ -54,7 +54,7 @@ func (s *UserTestSuite) SetupTest() {
ExpireSec: 0,
}
cfg := assembly.NewLocator(testInstance.Logger(), s.httpCli, s.db).
Config(context.Background(), emptyLdap, remote)
Config(context.Background(), emptyLdap, remote, time.Minute)
server, apiCli := grpct.TestServer(testInstance, cfg.Handler)
s.grpcCli = apiCli