You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

17 lines
481 B

  1. # frozen_string_literal: true
  2. class DistributionWorker
  3. include Sidekiq::Worker
  4. def perform(status_id, options = {})
  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), **options.symbolize_keys)
  8. else
  9. raise Mastodon::RaceConditionError
  10. end
  11. end
  12. rescue ActiveRecord::RecordNotFound
  13. true
  14. end
  15. end