mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-17 14:19:54 +05:00
Updated rpcclient library
This commit is contained in:
committed by
Dan Christian Bogos
parent
14336e29f5
commit
f353f12b68
@@ -109,6 +109,14 @@ func (at *ActionTiming) Clone() (cln *ActionTiming) {
|
||||
return
|
||||
}
|
||||
|
||||
// getDayOrEndOfMonth returns the day if is a valid date relative to t1 month
|
||||
func getDayOrEndOfMonth(day int, t1 time.Time) int {
|
||||
if lastDay := utils.GetEndOfMonth(t1).Day(); lastDay <= day { // clamp the day to last day of month in order to corectly compare the time
|
||||
day = lastDay
|
||||
}
|
||||
return day
|
||||
}
|
||||
|
||||
func (at *ActionTiming) GetNextStartTime(t1 time.Time) (t time.Time) {
|
||||
if !at.stCache.IsZero() {
|
||||
return at.stCache
|
||||
@@ -129,35 +137,17 @@ func (at *ActionTiming) GetNextStartTime(t1 time.Time) (t time.Time) {
|
||||
}
|
||||
at.stCache = cronexpr.MustParse(i.Timing.CronString()).Next(t1)
|
||||
if i.Timing.ID == utils.MetaMonthlyEstimated {
|
||||
day := at.Timing.Timing.MonthDays[0]
|
||||
if lastDay := utils.GetEndOfMonth(t1).Day(); lastDay <= day { // clamp the day to last day of month in order to corectly compare the time
|
||||
day = lastDay
|
||||
}
|
||||
// substract a month from at.stCache only if we skip 2 months
|
||||
// or we skip a month because mentioned MonthDay is after the last day of the current month
|
||||
if at.stCache.Month() == t1.Month()+2 ||
|
||||
(utils.GetEndOfMonth(t1).Day() < at.Timing.Timing.MonthDays[0] &&
|
||||
at.stCache.Month() == t1.Month()+1) {
|
||||
lastDay := utils.GetEndOfMonth(at.stCache).Day()
|
||||
at.stCache = at.stCache.AddDate(0, 0, -lastDay)
|
||||
}
|
||||
/*clnRITiming := at.Timing.Timing.Clone()
|
||||
mnt := t1.Month()
|
||||
day := clnRITiming.MonthDays[0]
|
||||
if lastDay := utils.GetEndOfMonth(t1).Day(); lastDay <= day { // clamp the day to last day of month in order to corectly compare the time
|
||||
day = lastDay
|
||||
}
|
||||
if t1.Day() > day || // in case we missed the day
|
||||
(t1.Day() == day && // did not miss the day but need to check if we missed the start time
|
||||
t1.Sub(t1.Truncate(24*time.Hour)) >=
|
||||
at.stCache.Sub(at.stCache.Truncate(24*time.Hour))) {
|
||||
// the StartTime is before t1 so try nextMonth
|
||||
if mnt++; mnt == 13 { // special case in case of december next month is January
|
||||
mnt = 1
|
||||
// only change the time if the new one is after t1
|
||||
if tmp := at.stCache.AddDate(0, 0, -lastDay); tmp.After(t1) {
|
||||
at.stCache = tmp
|
||||
}
|
||||
}
|
||||
for at.stCache.Month() > mnt {
|
||||
clnRITiming.MonthDays[0]--
|
||||
at.stCache = cronexpr.MustParse(clnRITiming.CronString()).Next(t1)
|
||||
}*/
|
||||
}
|
||||
return at.stCache
|
||||
}
|
||||
|
||||
@@ -3430,3 +3430,33 @@ func (dm *DataManager) GetAPIBan(ip string, apiKeys []string, single, cacheRead,
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// CheckFilters returns the filters IDs are valid
|
||||
func (dm *DataManager) CheckFilters(tenant string, ids []string) (ok bool) {
|
||||
for _, id := range ids {
|
||||
if strings.HasPrefix(id, utils.Meta) {
|
||||
if _, err := NewFilterFromInline(tenant, id); err != nil {
|
||||
return
|
||||
}
|
||||
} else if dm == nil {
|
||||
return
|
||||
} else if x, has := Cache.Get(utils.CacheFilters, utils.ConcatenatedKey(tenant, id)); has && x == nil {
|
||||
return
|
||||
} else if has, err := dm.DataDB().HasDataDrv(utils.FilterPrefix, id, tenant); err != nil || !has {
|
||||
if itm := config.CgrConfig().DataDbCfg().Items[utils.MetaFilters]; err == utils.ErrNotFound && itm.Remote {
|
||||
var fltr *Filter
|
||||
err = dm.connMgr.Call(config.CgrConfig().DataDbCfg().RmtConns, nil, utils.ReplicatorSv1GetFilter,
|
||||
&utils.TenantIDWithOpts{
|
||||
TenantID: &utils.TenantID{Tenant: tenant, ID: id},
|
||||
Opts: map[string]interface{}{
|
||||
utils.OptsAPIKey: itm.APIKey,
|
||||
utils.OptsRouteID: itm.RouteID,
|
||||
}}, &fltr)
|
||||
}
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user