about summary refs log tree commit diff
path: root/app/workers
diff options
context:
space:
mode:
authormultiple creatures <dev@multiple-creature.party>2019-07-23 16:48:08 -0500
committermultiple creatures <dev@multiple-creature.party>2019-07-23 16:48:08 -0500
commit3862f48c34a00691a12c6002abd88b088cf7c13e (patch)
treef1d5d2299de3d470816300221d3dba6ac8ecc30c /app/workers
parent2a6ccce070277c8c278a2e8403f45394eec06f91 (diff)
add self-destructing roars & `live`/`lifespan` bangtags
Diffstat (limited to 'app/workers')
-rw-r--r--app/workers/destruct_status_worker.rb16
-rw-r--r--app/workers/scheduler/destructing_statuses_scheduler.rb19
2 files changed, 35 insertions, 0 deletions
diff --git a/app/workers/destruct_status_worker.rb b/app/workers/destruct_status_worker.rb
new file mode 100644
index 000000000..6a3971220
--- /dev/null
+++ b/app/workers/destruct_status_worker.rb
@@ -0,0 +1,16 @@
+# frozen_string_literal: true
+
+class DestructStatusWorker
+  include Sidekiq::Worker
+
+  sidekiq_options unique: :until_executed
+
+  def perform(destructing_status_id)
+    destructing_status = DestructingStatus.find(destructing_status_id)
+    destructing_status.destroy!
+
+    RemoveStatusService.new.call(destructing_status.status)
+  rescue ActiveRecord::RecordNotFound, ActiveRecord::RecordInvalid
+    true
+  end
+end
diff --git a/app/workers/scheduler/destructing_statuses_scheduler.rb b/app/workers/scheduler/destructing_statuses_scheduler.rb
new file mode 100644
index 000000000..d79f97c33
--- /dev/null
+++ b/app/workers/scheduler/destructing_statuses_scheduler.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+class Scheduler::DestructingStatusesScheduler
+  include Sidekiq::Worker
+
+  sidekiq_options unique: :until_executed, retry: 0
+
+  def perform
+    due_statuses.find_each do |destructing_status|
+      DestructStatusWorker.perform_at(destructing_status.delete_after, destructing_status.id)
+    end
+  end
+
+  private
+
+  def due_statuses
+    DestructingStatus.where('delete_after <= ?', Time.now.utc + PostStatusService::MIN_DESTRUCT_OFFSET)
+  end
+end