2017-04-05 03:16:53 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class PushUpdateWorker
|
|
|
|
include Sidekiq::Worker
|
2022-01-19 21:37:27 +00:00
|
|
|
include Redisable
|
2017-04-05 03:16:53 +00:00
|
|
|
|
2022-01-19 21:37:27 +00:00
|
|
|
def perform(account_id, status_id, timeline_id = nil, options = {})
|
|
|
|
@account = Account.find(account_id)
|
|
|
|
@status = Status.find(status_id)
|
|
|
|
@timeline_id = timeline_id || "timeline:#{account.id}"
|
|
|
|
@options = options.symbolize_keys
|
2017-04-05 03:48:22 +00:00
|
|
|
|
2022-01-19 21:37:27 +00:00
|
|
|
publish!
|
2017-04-05 16:48:41 +00:00
|
|
|
rescue ActiveRecord::RecordNotFound
|
|
|
|
true
|
2017-04-05 03:16:53 +00:00
|
|
|
end
|
2022-01-19 21:37:27 +00:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def payload
|
|
|
|
InlineRenderer.render(@status, @account, :status)
|
|
|
|
end
|
|
|
|
|
|
|
|
def message
|
|
|
|
Oj.dump(
|
|
|
|
event: update? ? :'status.update' : :update,
|
|
|
|
payload: payload,
|
|
|
|
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 03:16:53 +00:00
|
|
|
end
|