publish_scheduled_announcement_worker.rb 756 B

12345678910111213141516171819202122232425262728
  1. # frozen_string_literal: true
  2. class PublishScheduledAnnouncementWorker
  3. include Sidekiq::Worker
  4. include Redisable
  5. def perform(announcement_id)
  6. @announcement = Announcement.find(announcement_id)
  7. refresh_status_ids!
  8. @announcement.publish! unless @announcement.published?
  9. payload = InlineRenderer.render(@announcement, nil, :announcement)
  10. payload = Oj.dump(event: :announcement, payload: payload)
  11. FeedManager.instance.with_active_accounts do |account|
  12. redis.publish("timeline:#{account.id}", payload) if redis.exists?("subscribed:timeline:#{account.id}")
  13. end
  14. end
  15. private
  16. def refresh_status_ids!
  17. @announcement.status_ids = Status.from_text(@announcement.text).map(&:id)
  18. @announcement.save
  19. end
  20. end