about summary refs log tree commit diff
path: root/app/workers/scheduler
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2019-01-05 12:43:28 +0100
committerGitHub <noreply@github.com>2019-01-05 12:43:28 +0100
commita49d43d1121ac10f96d5a9cbf78112c707e7a59e (patch)
treeee311cf3d68d695f6cc6c69ce9e1b01c6ad4aeb4 /app/workers/scheduler
parentb17b2f25acc4d0cd4284835f28364451cb2fcd88 (diff)
Add scheduled statuses (#9706)
Fix #340
Diffstat (limited to 'app/workers/scheduler')
-rw-r--r--app/workers/scheduler/scheduled_statuses_scheduler.rb19
1 files changed, 19 insertions, 0 deletions
diff --git a/app/workers/scheduler/scheduled_statuses_scheduler.rb b/app/workers/scheduler/scheduled_statuses_scheduler.rb
new file mode 100644
index 000000000..70a45846b
--- /dev/null
+++ b/app/workers/scheduler/scheduled_statuses_scheduler.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+class Scheduler::ScheduledStatusesScheduler
+  include Sidekiq::Worker
+
+  sidekiq_options unique: :until_executed, retry: 0
+
+  def perform
+    due_statuses.find_each do |scheduled_status|
+      PublishScheduledStatusWorker.perform_at(scheduled_status.scheduled_at)
+    end
+  end
+
+  private
+
+  def due_statuses
+    ScheduledStatus.where('scheduled_at <= ?', Time.now.utc + PostStatusService::MIN_SCHEDULE_OFFSET)
+  end
+end