-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UT new logic #4
UT new logic #4
Conversation
pkg/uptime-tracker/api/api.go
Outdated
@@ -153,6 +158,10 @@ func (api *API) RunBackgroundTasks(ctx context.Context, logger logrus.FieldLogge | |||
return | |||
case <-cacheTicker.C: | |||
api.updateInternalCaches(logger) | |||
if time.Now().Format("2006-01-02") > date { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If possible, I would like the routine to look like this:
oldestEntry := dbClient.Limit(1).Order("created_at asc")Find(&entry)
from := oldestEntry.createdAt.Format("2006-01-02")
to := time.Now().Add(0, 0 , -(storeCutoffDate))
if (from < to) {
for from; from < to; from.Add(0, 0, 1) {
dbClient.Limit(1).Where("date == from").FInd(&exportDate)
exportUptimeDayToStoreIfNotExist(exportDate)
dbClient.Delete(&exportDae)
}
}
This is just some leetcode to I am sure it needs to be adapted to work properly. But this way we have a few advantages:
- We always run the routine even if the uptime tracker gets restarted frequently, because we dont rely on the
date
variable that stored in memory - We always back up data even if its older than the
store-cutoff-date
and dont delete any data without backing up
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. Will do a round of integration testing and then merge if it works. 👍
Fixes: #2
Changes:
--store-data-cutoff
flag--store-data-path
for path of save daily data, default value is/var/lib/skywire-ut/daily-data
YYYY-MM-DD-uptime-data.json
decided to return old data as endpoint or store/upload in storageScreenshots:
How to test:
create_at
value of record to yesterday byupdate daily_uptime_histories set created_at = current_date - 1
api.dailyRoutine(logger)
to line 153 of api.go file, build and run UT again