vacuum_scheduler.rb 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # frozen_string_literal: true
  2. class Scheduler::VacuumScheduler
  3. include Sidekiq::Worker
  4. sidekiq_options retry: 0, lock: :until_executed, lock_ttl: 1.day.to_i
  5. def perform
  6. vacuum_operations.each do |operation|
  7. operation.perform
  8. rescue => e
  9. Rails.logger.error("Error while running #{operation.class.name}: #{e}")
  10. end
  11. end
  12. private
  13. def vacuum_operations
  14. [
  15. statuses_vacuum,
  16. media_attachments_vacuum,
  17. preview_cards_vacuum,
  18. backups_vacuum,
  19. access_tokens_vacuum,
  20. feeds_vacuum,
  21. imports_vacuum,
  22. ]
  23. end
  24. def statuses_vacuum
  25. Vacuum::StatusesVacuum.new(content_retention_policy.content_cache_retention_period)
  26. end
  27. def media_attachments_vacuum
  28. Vacuum::MediaAttachmentsVacuum.new(content_retention_policy.media_cache_retention_period)
  29. end
  30. def preview_cards_vacuum
  31. Vacuum::PreviewCardsVacuum.new(content_retention_policy.media_cache_retention_period)
  32. end
  33. def backups_vacuum
  34. Vacuum::BackupsVacuum.new(content_retention_policy.backups_retention_period)
  35. end
  36. def access_tokens_vacuum
  37. Vacuum::AccessTokensVacuum.new
  38. end
  39. def feeds_vacuum
  40. Vacuum::FeedsVacuum.new
  41. end
  42. def imports_vacuum
  43. Vacuum::ImportsVacuum.new
  44. end
  45. def content_retention_policy
  46. ContentRetentionPolicy.current
  47. end
  48. end