You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
813 B

  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. queued_at: (Time.now.to_f * 1000.0).to_i
  24. )
  25. end
  26. def publish!
  27. redis.publish(@timeline_id, message)
  28. end
  29. def update?
  30. @options[:update]
  31. end
  32. end