push_update_worker.rb 783 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. # frozen_string_literal: true
  2. class PushUpdateWorker
  3. include Sidekiq::Worker
  4. include Redisable
  5. def perform(account_id, status_id, timeline_id = nil, options = {})
  6. @account = Account.find(account_id)
  7. @status = Status.find(status_id)
  8. @timeline_id = timeline_id || "timeline:#{account.id}"
  9. @options = options.symbolize_keys
  10. publish!
  11. rescue ActiveRecord::RecordNotFound
  12. true
  13. end
  14. private
  15. def payload
  16. InlineRenderer.render(@status, @account, :status)
  17. end
  18. def message
  19. Oj.dump(
  20. event: update? ? :'status.update' : :update,
  21. payload: payload,
  22. queued_at: (Time.now.to_f * 1000.0).to_i
  23. )
  24. end
  25. def publish!
  26. redis.publish(@timeline_id, message)
  27. end
  28. def update?
  29. @options[:update]
  30. end
  31. end