2017-04-05 13:16:53 +10:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class PushUpdateWorker
|
|
|
|
include Sidekiq::Worker
|
2022-01-20 08:37:27 +11:00
|
|
|
include Redisable
|
2017-04-05 13:16:53 +10:00
|
|
|
|
2022-01-20 08:37:27 +11:00
|
|
|
def perform(account_id, status_id, timeline_id = nil, options = {})
|
2022-11-04 23:21:06 +11:00
|
|
|
@status = Status.find(status_id)
|
|
|
|
@account_id = account_id
|
|
|
|
@timeline_id = timeline_id || "timeline:#{account_id}"
|
2022-01-20 08:37:27 +11:00
|
|
|
@options = options.symbolize_keys
|
2017-04-05 13:48:22 +10:00
|
|
|
|
2022-11-04 23:21:06 +11:00
|
|
|
render_payload!
|
2022-01-20 08:37:27 +11:00
|
|
|
publish!
|
2017-04-06 02:48:41 +10:00
|
|
|
rescue ActiveRecord::RecordNotFound
|
|
|
|
true
|
2017-04-05 13:16:53 +10:00
|
|
|
end
|
2022-01-20 08:37:27 +11:00
|
|
|
|
|
|
|
private
|
|
|
|
|
2022-11-04 23:21:06 +11:00
|
|
|
def render_payload!
|
|
|
|
@payload = StatusCacheHydrator.new(@status).hydrate(@account_id)
|
2022-01-20 08:37:27 +11:00
|
|
|
end
|
|
|
|
|
|
|
|
def message
|
|
|
|
Oj.dump(
|
|
|
|
event: update? ? :'status.update' : :update,
|
2022-11-04 23:21:06 +11:00
|
|
|
payload: @payload,
|
2022-01-20 08:37:27 +11:00
|
|
|
queued_at: (Time.now.to_f * 1000.0).to_i
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
def publish!
|
|
|
|
redis.publish(@timeline_id, message)
|
|
|
|
end
|
|
|
|
|
|
|
|
def update?
|
|
|
|
@options[:update]
|
|
|
|
end
|
2017-04-05 13:16:53 +10:00
|
|
|
end
|