mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-15 13:19:53 +05:00
Use channel instead of context to handle shutdown
This commit is contained in:
committed by
Dan Christian Bogos
parent
d9359a4005
commit
c8a3ebe5e8
@@ -265,20 +265,20 @@ func (chS *CacheS) GetPrecacheChannel(chID string) chan struct{} {
|
||||
}
|
||||
|
||||
// Precache loads data from DataDB into cache at engine start
|
||||
func (chS *CacheS) Precache(ctx *context.Context, shutdown context.CancelFunc) {
|
||||
func (chS *CacheS) Precache(shutdown chan struct{}) {
|
||||
for cacheID, cacheCfg := range chS.cfg.CacheCfg().Partitions {
|
||||
if !cacheCfg.Precache {
|
||||
close(chS.pcItems[cacheID]) // no need of precache
|
||||
continue
|
||||
}
|
||||
go func(cacheID string) {
|
||||
err := chS.dm.CacheDataFromDB(ctx,
|
||||
err := chS.dm.CacheDataFromDB(context.TODO(),
|
||||
utils.CacheInstanceToPrefix[cacheID],
|
||||
[]string{utils.MetaAny},
|
||||
false)
|
||||
if err != nil && err != context.Canceled {
|
||||
utils.Logger.Crit(fmt.Sprintf("<%s> precaching cacheID <%s>, got error: %s", utils.CacheS, cacheID, err))
|
||||
shutdown()
|
||||
close(shutdown)
|
||||
return
|
||||
}
|
||||
close(chS.pcItems[cacheID])
|
||||
|
||||
@@ -1373,7 +1373,7 @@ func TestCacheSPrecachePartitions(t *testing.T) {
|
||||
if _, err := dm.GetAttributeProfile(context.Background(), utils.CGRateSorg, "TEST_ATTRIBUTES_TEST", true, true, utils.NonTransactional); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
cacheS.Precache(context.Background(), func() {})
|
||||
cacheS.Precache(make(chan struct{}))
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
|
||||
if rcv, ok := Cache.Get(utils.CacheAttributeProfiles, "cgrates.org:TEST_ATTRIBUTES_TEST"); !ok {
|
||||
@@ -1400,10 +1400,6 @@ func TestCacheSPrecacheErr(t *testing.T) {
|
||||
|
||||
args := &utils.ArgCacheReplicateSet{
|
||||
CacheID: utils.CacheAccounts,
|
||||
ItemID: "itemID",
|
||||
Value: &utils.CachedRPCResponse{
|
||||
Result: "reply",
|
||||
Error: nil},
|
||||
}
|
||||
cfg := config.NewDefaultCGRConfig()
|
||||
cfg.CacheCfg().Partitions = map[string]*config.CacheParamCfg{
|
||||
@@ -1414,7 +1410,7 @@ func TestCacheSPrecacheErr(t *testing.T) {
|
||||
|
||||
cacheS := NewCacheS(cfg, nil, connMgr, nil)
|
||||
|
||||
cacheS.Precache(context.Background(), func() {})
|
||||
cacheS.Precache(make(chan struct{}))
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
expErr := "<CacheS> precaching cacheID <*accounts>, got error: NO_DATABASE_CONNECTION"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user