File tree Expand file tree Collapse file tree 1 file changed +6
-2
lines changed
Expand file tree Collapse file tree 1 file changed +6
-2
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments