gearheads
/
mastodon
Archived
2
0
Fork 0
This repository has been archived on 2024-06-09. You can view files and clone it, but cannot push or open issues/pull-requests.
mastodon/app/workers/push_update_worker.rb

40 lines
783 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 = {})
@account = Account.find(account_id)
@status = Status.find(status_id)
@timeline_id = timeline_id || "timeline:#{account.id}"
@options = options.symbolize_keys
2017-04-05 05:48:22 +02:00
publish!
rescue ActiveRecord::RecordNotFound
true
end
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
end