about summary refs log tree commit diff
path: root/app/workers/scheduler/scheduled_statuses_scheduler.rb
diff options
context:
space:
mode:
authorpluralcafe-docker <git@plural.cafe>2019-01-12 04:24:14 +0000
committerpluralcafe-docker <git@plural.cafe>2019-01-12 04:24:14 +0000
commitae24ef877b82466cab026a76ea6ed8598ddaae18 (patch)
tree584c25ada377f2e6da49a9b45b3da947501b1831 /app/workers/scheduler/scheduled_statuses_scheduler.rb
parentfa1ab7fbe4166f3d8b481891dcc443df5aa212bb (diff)
parent2cfa55185a5fc7d93a160a4e9a4730aae6725b0f (diff)
Merge branch 'glitch'
Diffstat (limited to 'app/workers/scheduler/scheduled_statuses_scheduler.rb')
-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..1772a246b
--- /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, scheduled_status.id)
+    end
+  end
+
+  private
+
+  def due_statuses
+    ScheduledStatus.where('scheduled_at <= ?', Time.now.utc + PostStatusService::MIN_SCHEDULE_OFFSET)
+  end
+end