Skip to content

Commit 2bed7b5

Browse files
yashmehrotramoshloop
authored andcommitted
fix: ignore linked config_items when deleting config scraper
1 parent d6de38b commit 2bed7b5

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

jobs/cleanup.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,14 @@ var CleanupConfigScrapers = &job.Job{
187187
}
188188
}
189189

190-
// Hard delete old config scrapers
190+
// Hard delete old config scrapers that have no remaining config_items references
191191
retention := ctx.Properties().Duration("config_scraper.retention.period", (time.Hour * 24 * time.Duration(ConfigScraperRetentionDays)))
192192
days := int64(retention.Hours() / 24)
193-
if err := ctx.DB().Exec(`DELETE FROM config_scrapers WHERE (NOW() - deleted_at ) > INTERVAL '1 day' * ?`, days).Error; err != nil {
193+
if err := ctx.DB().Exec(`
194+
DELETE FROM config_scrapers
195+
WHERE (NOW() - deleted_at) > INTERVAL '1 day' * ?
196+
AND id NOT IN (SELECT DISTINCT scraper_id FROM config_items WHERE scraper_id IS NOT NULL)
197+
`, days).Error; err != nil {
194198
ctx.History.AddErrorf("error hard deleting config_scrapers: %v", err)
195199
}
196200

0 commit comments

Comments
 (0)