about summary refs log tree commit diff
path: root/app/workers
diff options
context:
space:
mode:
authormultiple creatures <dev@multiple-creature.party>2019-08-30 22:03:46 -0500
committermultiple creatures <dev@multiple-creature.party>2019-08-30 22:03:46 -0500
commit3b276d268f8e49b897f16f490c78a5a5880c6216 (patch)
treebcb653e975ab223cf8d048778ab113489bf67b6d /app/workers
parent60c449e1d77c6e11ced796a7e088038d80137de6 (diff)
use a scheduled task to batch domain policy changes + revert `29643fd6` to avoid accidentally dosing servers when multiple users block a domain
Diffstat (limited to 'app/workers')
-rw-r--r--app/workers/after_account_domain_unblock_worker.rb11
-rw-r--r--app/workers/scheduler/domain_policy_scheduler.rb11
-rw-r--r--app/workers/scheduler/janitor_scheduler.rb1
-rw-r--r--app/workers/update_account_domain_blocks_worker.rb11
4 files changed, 11 insertions, 23 deletions
diff --git a/app/workers/after_account_domain_unblock_worker.rb b/app/workers/after_account_domain_unblock_worker.rb
deleted file mode 100644
index 6268f0819..000000000
--- a/app/workers/after_account_domain_unblock_worker.rb
+++ /dev/null
@@ -1,11 +0,0 @@
-# frozen_string_literal: true
-
-class AfterAccountDomainUnblockWorker
-  include Sidekiq::Worker
-
-  def perform(account_id, domain)
-    AfterUnblockDomainFromAccountService.new.call(Account.find(account_id), domain)
-  rescue ActiveRecord::RecordNotFound
-    true
-  end
-end
diff --git a/app/workers/scheduler/domain_policy_scheduler.rb b/app/workers/scheduler/domain_policy_scheduler.rb
new file mode 100644
index 000000000..c7c0b5e62
--- /dev/null
+++ b/app/workers/scheduler/domain_policy_scheduler.rb
@@ -0,0 +1,11 @@
+# frozen_string_literal: true
+
+class Scheduler::DomainPolicyScheduler
+  include Sidekiq::Worker
+
+  sidekiq_options unique: :until_executed
+
+  def perform
+    DomainBlock.unprocessed.find_each { |policy| BlockDomainService.new.call(policy) }
+  end
+end
diff --git a/app/workers/scheduler/janitor_scheduler.rb b/app/workers/scheduler/janitor_scheduler.rb
index 6a386b30a..3411ec26b 100644
--- a/app/workers/scheduler/janitor_scheduler.rb
+++ b/app/workers/scheduler/janitor_scheduler.rb
@@ -59,7 +59,6 @@ class Scheduler::JanitorScheduler
     blocks.each do |entry|
       next unless domain_exists?(entry[:domain])
       block = DomainBlock.create!(entry)
-      DomainBlockWorker.perform_async(block)
       Admin::ActionLog.create(account: @account, action: :create, target: block)
       user_friendly_action_log(@account, :create, block)
     end
diff --git a/app/workers/update_account_domain_blocks_worker.rb b/app/workers/update_account_domain_blocks_worker.rb
deleted file mode 100644
index 14d4e8516..000000000
--- a/app/workers/update_account_domain_blocks_worker.rb
+++ /dev/null
@@ -1,11 +0,0 @@
-# frozen_string_literal: true
-
-class UpdateAccountDomainBlocksWorker
-  include Sidekiq::Worker
-
-  def perform(account_id)
-    UpdateAccountDomainBlocksService.new.call(Account.find(account_id))
-  rescue ActiveRecord::RecordNotFound
-    true
-  end
-end