Skip to content

Commit

Permalink
APIGOV-26081 - updates needed fixing from testing
Browse files Browse the repository at this point in the history
  • Loading branch information
sbolosan committed Aug 21, 2023
1 parent 7f4f2d0 commit be35602
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
12 changes: 2 additions & 10 deletions pkg/agent/eventsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,16 +145,8 @@ func (es *EventSync) RebuildCache() {

agentInstance := agent.agentResourceManager.GetAgentResource()

// x-agent-details "cacheUpdateTime" key doesn't exist, set current cache time to now
currentCacheUpdateTime := time.Now()
value, _ := util.GetAgentDetailsValue(agentInstance, "cacheUpdateTime")
// otherwise, get the current value from "cacheUpdateTime"
if value != "" {
currentCacheUpdateTime, _ = time.Parse(time.RFC3339, value)
}

// add 7 days to the "cacheUpdateTime"
nextCacheUpdateTime := currentCacheUpdateTime.Add(7 * 24 * time.Hour)
// add 7 days to the current date for the next rebuild cache
nextCacheUpdateTime := time.Now().Add(7 * 24 * time.Hour)

// persist cacheUpdateTime
util.SetAgentDetailsKey(agentInstance, "cacheUpdateTime", strconv.FormatInt(nextCacheUpdateTime.UnixNano(), 10))
Expand Down
21 changes: 17 additions & 4 deletions pkg/agent/resource/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package resource

import (
"fmt"
"os"
"strconv"
"strings"
"time"
Expand All @@ -17,6 +18,9 @@ import (
"github.com/Axway/agent-sdk/pkg/util/log"
)

// QA EnvVars
const qaTriggerSevenDayRefreshCache = "QA_CENTRAL_TRIGGER_REFRESH_CACHE"

type EventSyncCache interface {
RebuildCache()
}
Expand Down Expand Up @@ -177,11 +181,10 @@ func (a *agentResourceManager) shouldRebuildCache() (bool, error) {
return false, err
}
currentCacheUpdateTime := time.Unix(0, convToTimestamp)
plusSevenDays := currentCacheUpdateTime.Add(7 * 24 * time.Hour)
a.logger.Tracef("the current scheduled refresh cache date - %s", time.Unix(0, plusSevenDays.UnixNano()).Format("2006-01-02 15:04:05.000000"))
a.logger.Tracef("the current scheduled refresh cache date - %s", time.Unix(0, currentCacheUpdateTime.UnixNano()).Format("2006-01-02 15:04:05.000000"))

// check to see if 7 days have passed since last refresh cache
if time.Now().UnixNano() > plusSevenDays.UnixNano() {
// check to see if 7 days have passed since last refresh cache. currentCacheUpdateTime is the date at the time we rebuilt cache plus 7 days(in event sync - RebuildCache)
if a.getCurrentTime() > currentCacheUpdateTime.UnixNano() {
a.logger.Trace("the current date is greater than the current scheduled refresh date - time to rebuild cache")
rebuildCache = true
}
Expand All @@ -197,6 +200,16 @@ func (a *agentResourceManager) shouldRebuildCache() (bool, error) {
return rebuildCache, nil
}

func (a *agentResourceManager) getCurrentTime() int64 {
val := os.Getenv(qaTriggerSevenDayRefreshCache)
if val == "" {
// if this isn't set, then just pass back the current time
return time.Now().UnixNano()
}
// if this is set, then pass back the current time, plus 7 days to trigger a rebuild
return time.Now().Add(7 * 24 * time.Hour).UnixNano()
}

// GetAgentDetails - Gets current agent details
func (a *agentResourceManager) GetAgentDetails() map[string]interface{} {
return a.agentDetails
Expand Down

0 comments on commit be35602

Please sign in to comment.