updated logs delete trigger frequency and tests
This commit is contained in:
parent
b0f8c78022
commit
1f08b70283
|
@ -1258,14 +1258,12 @@ func (app *BaseApp) initLogger() error {
|
||||||
|
|
||||||
// @todo replace with cron so that it doesn't rely on the logs write
|
// @todo replace with cron so that it doesn't rely on the logs write
|
||||||
//
|
//
|
||||||
// delete old logs (~ once 1 day)
|
// delete old logs (~ twice a day)
|
||||||
// ---
|
// ---
|
||||||
logsMaxDays := app.Settings().Logs.MaxDays
|
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
lastLogsDeletedAt := cast.ToTime(app.Store().Get("lastLogsDeletedAt"))
|
lastLogsDeletedAt := cast.ToTime(app.Store().Get("lastLogsDeletedAt"))
|
||||||
daysDiff := now.Sub(lastLogsDeletedAt).Hours() / 24
|
if now.Sub(lastLogsDeletedAt).Hours() >= 6 {
|
||||||
if daysDiff >= 1 {
|
deleteErr := app.LogsDao().DeleteOldLogs(now.AddDate(0, 0, -1*app.Settings().Logs.MaxDays))
|
||||||
deleteErr := app.LogsDao().DeleteOldLogs(now.AddDate(0, 0, -1*logsMaxDays))
|
|
||||||
if deleteErr == nil {
|
if deleteErr == nil {
|
||||||
app.Store().Set("lastLogsDeletedAt", now)
|
app.Store().Set("lastLogsDeletedAt", now)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -380,7 +380,7 @@ func TestBaseAppLoggerWrites(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// simulate recently deleted logs
|
// simulate recently deleted logs
|
||||||
app.Store().Set("lastLogsDeletedAt", time.Now())
|
app.Store().Set("lastLogsDeletedAt", time.Now().Add(-5*time.Hour))
|
||||||
|
|
||||||
// trigger batch write (B)
|
// trigger batch write (B)
|
||||||
for i := 0; i < logsThreshold; i++ {
|
for i := 0; i < logsThreshold; i++ {
|
||||||
|
@ -407,7 +407,7 @@ func TestBaseAppLoggerWrites(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// should trigger delete on the next batch write
|
// should trigger delete on the next batch write
|
||||||
app.Store().Set("lastLogsDeletedAt", time.Now().AddDate(0, 0, -1))
|
app.Store().Set("lastLogsDeletedAt", time.Now().Add(-6*time.Hour))
|
||||||
|
|
||||||
// trigger batch write (C)
|
// trigger batch write (C)
|
||||||
for i := 0; i < logsThreshold; i++ {
|
for i := 0; i < logsThreshold; i++ {
|
||||||
|
|
Loading…
Reference in New Issue