distribution_worker.rb 441 B

1234567891011121314151617
  1. # frozen_string_literal: true
  2. class DistributionWorker
  3. include Sidekiq::Worker
  4. def perform(status_id)
  5. RedisLock.acquire(redis: Redis.current, key: "distribute:#{status_id}", autorelease: 5.minutes.seconds) do |lock|
  6. if lock.acquired?
  7. FanOutOnWriteService.new.call(Status.find(status_id))
  8. else
  9. raise Mastodon::RaceConditionError
  10. end
  11. end
  12. rescue ActiveRecord::RecordNotFound
  13. true
  14. end
  15. end