Delete expired vulnerability exports daily

What does this MR do and why?

Vulnerability exports which have been delivered asynchronously will expire after 7 days. This implements a worker which will clean up all expired exports daily. Exports which were downloaded synchronously will have a null expires_at column and should not be deleted.

SQL

https://console.postgres.ai/gitlab/gitlab-production-main/sessions/36987/commands/113506

In production, there are currently no records that can be deleted. expires_at is being set in !183169 (merged) and until the feature flag is turned on, exports are deleted after one hour.

DELETE FROM vulnerability_exports
WHERE
    vulnerability_exports.expires_at <= '2025-03-10 13:54:00' AND
    vulnerability_exports.id >= 1;

References

  • #454794

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

How to set up and validate locally

  1. Start the rails console: bundle exec rails c
  2. Create records and run the deletion worker:
project = Project.last
author = User.last
records = FactoryBot.create_list(:vulnerability_export, 5, expires_at: 1.hour.ago, project: project, author: author)
Vulnerabilities::DeleteExpiredExportsWorker.new.perform
records.map { |r| r.class.exists?(r.id) }
Edited by Ugo Nnanna Okeadu

Merge request reports

Loading