push_update_worker.rb 765 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. @status = Status.find(status_id)
  7. @account_id = account_id
  8. @timeline_id = timeline_id || "timeline:#{account_id}"
  9. @options = options.symbolize_keys
  10. render_payload!
  11. publish!
  12. rescue ActiveRecord::RecordNotFound
  13. true
  14. end
  15. private
  16. def render_payload!
  17. @payload = StatusCacheHydrator.new(@status).hydrate(@account_id)
  18. end
  19. def message
  20. Oj.dump(
  21. event: update? ? :'status.update' : :update,
  22. payload: @payload
  23. )
  24. end
  25. def publish!
  26. redis.publish(@timeline_id, message)
  27. end
  28. def update?
  29. @options[:update]
  30. end
  31. end