1
0
mirror of https://github.com/funamitech/mastodon synced 2024-12-12 13:48:35 +09:00
YuruToot/app/workers/push_update_worker.rb

40 lines
765 B
Ruby
Raw Normal View History

# frozen_string_literal: true
class PushUpdateWorker
include Sidekiq::Worker
include Redisable
def perform(account_id, status_id, timeline_id = nil, options = {})
@status = Status.find(status_id)
@account_id = account_id
@timeline_id = timeline_id || "timeline:#{account_id}"
@options = options.symbolize_keys
2017-04-05 12:48:22 +09:00
render_payload!
publish!
rescue ActiveRecord::RecordNotFound
true
end
private
def render_payload!
@payload = StatusCacheHydrator.new(@status).hydrate(@account_id)
end
def message
Oj.dump(
event: update? ? :'status.update' : :update,
payload: @payload
)
end
def publish!
redis.publish(@timeline_id, message)
end
def update?
@options[:update]
end
end