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.

39 lines
783 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. @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