about summary refs log tree commit diff
path: root/app/workers/scheduler
diff options
context:
space:
mode:
authorClaire <claire.github-309c@sitedethib.com>2022-10-02 17:33:37 +0200
committerClaire <claire.github-309c@sitedethib.com>2022-10-02 18:46:22 +0200
commit221580a3afb62b8da047b4feddbb58261ca07fbc (patch)
treebb070ba3e04a4cea5a7f55257ebe3cf71b2df280 /app/workers/scheduler
parent9d7c323abdda66423751f3a25faf960674af8a49 (diff)
parentc55219efa811b3c6347774bec1b174d325e5f300 (diff)
Merge branch 'main' into glitch-soc/merge-upstream
Conflicts:
- `app/controllers/home_controller.rb`:
  Upstream made it so `/web` is available to non-logged-in users
  and `/` redirects to `/web` instead of `/about`.
  Kept our version since glitch-soc's WebUI doesn't have what's
  needed yet and I think /about is still a much better landing
  page anyway.
- `app/models/form/admin_settings.rb`:
  Upstream added new settings, and glitch-soc had an extra setting.
  Not really a conflict.
  Added upstream's new settings.
- `app/serializers/initial_state_serializer.rb`:
  Upstream added a new `server` initial state object.
  Not really a conflict.
  Merged upstream's changes.
- `app/views/admin/settings/edit.html.haml`:
  Upstream added new settings.
  Not really a conflict.
  Merged upstream's changes.
- `app/workers/scheduler/feed_cleanup_scheduler.rb`:
  Upstream refactored that part and removed the file.
  Ported our relevant changes into `app/lib/vacuum/feeds_vacuum.rb`
- `config/settings.yml`:
  Upstream added new settings.
  Not a real conflict.
  Added upstream's new settings.
Diffstat (limited to 'app/workers/scheduler')
-rw-r--r--app/workers/scheduler/backup_cleanup_scheduler.rb17
-rw-r--r--app/workers/scheduler/doorkeeper_cleanup_scheduler.rb13
-rw-r--r--app/workers/scheduler/feed_cleanup_scheduler.rb40
-rw-r--r--app/workers/scheduler/media_cleanup_scheduler.rb17
-rw-r--r--app/workers/scheduler/vacuum_scheduler.rb56
5 files changed, 56 insertions, 87 deletions
diff --git a/app/workers/scheduler/backup_cleanup_scheduler.rb b/app/workers/scheduler/backup_cleanup_scheduler.rb
deleted file mode 100644
index 85d5312c0..000000000
--- a/app/workers/scheduler/backup_cleanup_scheduler.rb
+++ /dev/null
@@ -1,17 +0,0 @@
-# frozen_string_literal: true
-
-class Scheduler::BackupCleanupScheduler
-  include Sidekiq::Worker
-
-  sidekiq_options retry: 0
-
-  def perform
-    old_backups.reorder(nil).find_each(&:destroy!)
-  end
-
-  private
-
-  def old_backups
-    Backup.where('created_at < ?', 7.days.ago)
-  end
-end
diff --git a/app/workers/scheduler/doorkeeper_cleanup_scheduler.rb b/app/workers/scheduler/doorkeeper_cleanup_scheduler.rb
deleted file mode 100644
index 9303a352f..000000000
--- a/app/workers/scheduler/doorkeeper_cleanup_scheduler.rb
+++ /dev/null
@@ -1,13 +0,0 @@
-# frozen_string_literal: true
-
-class Scheduler::DoorkeeperCleanupScheduler
-  include Sidekiq::Worker
-
-  sidekiq_options retry: 0
-
-  def perform
-    Doorkeeper::AccessToken.where('revoked_at IS NOT NULL').where('revoked_at < NOW()').delete_all
-    Doorkeeper::AccessGrant.where('revoked_at IS NOT NULL').where('revoked_at < NOW()').delete_all
-    SystemKey.expired.delete_all
-  end
-end
diff --git a/app/workers/scheduler/feed_cleanup_scheduler.rb b/app/workers/scheduler/feed_cleanup_scheduler.rb
deleted file mode 100644
index 78adc97e2..000000000
--- a/app/workers/scheduler/feed_cleanup_scheduler.rb
+++ /dev/null
@@ -1,40 +0,0 @@
-# frozen_string_literal: true
-
-class Scheduler::FeedCleanupScheduler
-  include Sidekiq::Worker
-  include Redisable
-
-  sidekiq_options retry: 0
-
-  def perform
-    clean_home_feeds!
-    clean_list_feeds!
-    clean_direct_feeds!
-  end
-
-  private
-
-  def clean_home_feeds!
-    feed_manager.clean_feeds!(:home, inactive_account_ids)
-  end
-
-  def clean_list_feeds!
-    feed_manager.clean_feeds!(:list, inactive_list_ids)
-  end
-
-  def clean_direct_feeds!
-    feed_manager.clean_feeds!(:direct, inactive_account_ids)
-  end
-
-  def inactive_account_ids
-    @inactive_account_ids ||= User.confirmed.inactive.pluck(:account_id)
-  end
-
-  def inactive_list_ids
-    List.where(account_id: inactive_account_ids).pluck(:id)
-  end
-
-  def feed_manager
-    FeedManager.instance
-  end
-end
diff --git a/app/workers/scheduler/media_cleanup_scheduler.rb b/app/workers/scheduler/media_cleanup_scheduler.rb
deleted file mode 100644
index 24d30a6be..000000000
--- a/app/workers/scheduler/media_cleanup_scheduler.rb
+++ /dev/null
@@ -1,17 +0,0 @@
-# frozen_string_literal: true
-
-class Scheduler::MediaCleanupScheduler
-  include Sidekiq::Worker
-
-  sidekiq_options retry: 0
-
-  def perform
-    unattached_media.find_each(&:destroy)
-  end
-
-  private
-
-  def unattached_media
-    MediaAttachment.reorder(nil).unattached.where('created_at < ?', 1.day.ago)
-  end
-end
diff --git a/app/workers/scheduler/vacuum_scheduler.rb b/app/workers/scheduler/vacuum_scheduler.rb
new file mode 100644
index 000000000..ce88ff204
--- /dev/null
+++ b/app/workers/scheduler/vacuum_scheduler.rb
@@ -0,0 +1,56 @@
+# frozen_string_literal: true
+
+class Scheduler::VacuumScheduler
+  include Sidekiq::Worker
+
+  sidekiq_options retry: 0
+
+  def perform
+    vacuum_operations.each do |operation|
+      operation.perform
+    rescue => e
+      Rails.logger.error("Error while running #{operation.class.name}: #{e}")
+    end
+  end
+
+  private
+
+  def vacuum_operations
+    [
+      statuses_vacuum,
+      media_attachments_vacuum,
+      preview_cards_vacuum,
+      backups_vacuum,
+      access_tokens_vacuum,
+      feeds_vacuum,
+    ]
+  end
+
+  def statuses_vacuum
+    Vacuum::StatusesVacuum.new(content_retention_policy.content_cache_retention_period)
+  end
+
+  def media_attachments_vacuum
+    Vacuum::MediaAttachmentsVacuum.new(content_retention_policy.media_cache_retention_period)
+  end
+
+  def preview_cards_vacuum
+    Vacuum::PreviewCardsVacuum.new(content_retention_policy.media_cache_retention_period)
+  end
+
+  def backups_vacuum
+    Vacuum::BackupsVacuum.new(content_retention_policy.backups_retention_period)
+  end
+
+  def access_tokens_vacuum
+    Vacuum::AccessTokensVacuum.new
+  end
+
+  def feeds_vacuum
+    Vacuum::FeedsVacuum.new
+  end
+
+  def content_retention_policy
+    ContentRetentionPolicy.current
+  end
+end