about summary refs log tree commit diff
path: root/app/workers/scheduler
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2019-07-15 07:50:14 +0200
committerGitHub <noreply@github.com>2019-07-15 07:50:14 +0200
commitb3f44aa186487b4f93f3a457607870c90caaf5df (patch)
treed543cf8a81a9ceddd64f075ae9a269916aadceab /app/workers/scheduler
parentcecd0c3cb1ed208b3291342d644128c8fe71f12d (diff)
Add periodic removal of older thumbnails for preview cards (#11304)
Diffstat (limited to 'app/workers/scheduler')
-rw-r--r--app/workers/scheduler/preview_cards_cleanup_scheduler.rb22
1 files changed, 22 insertions, 0 deletions
diff --git a/app/workers/scheduler/preview_cards_cleanup_scheduler.rb b/app/workers/scheduler/preview_cards_cleanup_scheduler.rb
new file mode 100644
index 000000000..2b38792f0
--- /dev/null
+++ b/app/workers/scheduler/preview_cards_cleanup_scheduler.rb
@@ -0,0 +1,22 @@
+# frozen_string_literal: true
+
+class Scheduler::PreviewCardsCleanupScheduler
+  include Sidekiq::Worker
+
+  sidekiq_options unique: :until_executed, retry: 0
+
+  def perform
+    Maintenance::UncachePreviewWorker.push_bulk(recent_link_preview_cards.pluck(:id))
+    Maintenance::UncachePreviewWorker.push_bulk(older_preview_cards.pluck(:id))
+  end
+
+  private
+
+  def recent_link_preview_cards
+    PreviewCard.where(type: :link).where('updated_at < ?', 1.month.ago)
+  end
+
+  def older_preview_cards
+    PreviewCard.where('updated_at < ?', 6.months.ago)
+  end
+end