1
0

vacuum_scheduler.rb 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. applications_vacuum,
  21. feeds_vacuum,
  22. imports_vacuum,
  23. ]
  24. end
  25. def statuses_vacuum
  26. Vacuum::StatusesVacuum.new(content_retention_policy.content_cache_retention_period)
  27. end
  28. def media_attachments_vacuum
  29. Vacuum::MediaAttachmentsVacuum.new(content_retention_policy.media_cache_retention_period)
  30. end
  31. def preview_cards_vacuum
  32. Vacuum::PreviewCardsVacuum.new(content_retention_policy.media_cache_retention_period)
  33. end
  34. def backups_vacuum
  35. Vacuum::BackupsVacuum.new(content_retention_policy.backups_retention_period)
  36. end
  37. def access_tokens_vacuum
  38. Vacuum::AccessTokensVacuum.new
  39. end
  40. def feeds_vacuum
  41. Vacuum::FeedsVacuum.new
  42. end
  43. def imports_vacuum
  44. Vacuum::ImportsVacuum.new
  45. end
  46. def applications_vacuum
  47. Vacuum::ApplicationsVacuum.new
  48. end
  49. def content_retention_policy
  50. ContentRetentionPolicy.current
  51. end
  52. end