jobs: add config cleanup job (#19987)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
282c2b94a9
Коммит
6ab7cd0f1a
@@ -1113,3 +1113,50 @@ func TestDatabaseStoreString(t *testing.T) {
|
||||
assert.False(t, strings.Contains(maskedDSN, "mostest"))
|
||||
}
|
||||
}
|
||||
|
||||
func TestCleanUp(t *testing.T) {
|
||||
_, tearDown := setupConfigDatabase(t, emptyConfig, nil)
|
||||
defer tearDown()
|
||||
|
||||
ds, err := newTestDatabaseStore(nil)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, ds)
|
||||
defer ds.Close()
|
||||
|
||||
dbs, ok := ds.backingStore.(*DatabaseStore)
|
||||
require.True(t, ok, "should be a DatabaseStore instance")
|
||||
|
||||
b, err := marshalConfig(ds.config)
|
||||
require.NoError(t, err)
|
||||
|
||||
ds.config.JobSettings.CleanupConfigThresholdDays = model.NewInt(30) // we set 30 days as threshold
|
||||
|
||||
now := time.Now()
|
||||
for i := 0; i < 5; i++ {
|
||||
// 20 days, we expect to remove at least 3 configuration values from the store
|
||||
// first 2 (0 and 1) will be within a month constraint, others will be older than
|
||||
// a month hence we expect 3 configurations to be removed from the database.
|
||||
m := -1 * i * 24 * 20
|
||||
params := map[string]interface{}{
|
||||
"id": model.NewId(),
|
||||
"value": string(b),
|
||||
"create_at": model.GetMillisForTime(now.Add(time.Duration(m) * time.Hour)),
|
||||
}
|
||||
|
||||
_, err = dbs.db.NamedExec("INSERT INTO Configurations (Id, Value, CreateAt) VALUES (:id, :value, :create_at)", params)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
var initialCount int
|
||||
row := dbs.db.QueryRow("SELECT COUNT(*) FROM Configurations")
|
||||
err = row.Scan(&initialCount)
|
||||
require.NoError(t, err)
|
||||
|
||||
err = ds.CleanUp()
|
||||
require.NoError(t, err)
|
||||
|
||||
var count int
|
||||
row = dbs.db.QueryRow("SELECT COUNT(*) FROM Configurations")
|
||||
err = row.Scan(&count)
|
||||
require.NoError(t, err)
|
||||
require.True(t, count+3 == initialCount)
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user