gab-social/app/services/delete_preview_card_service.rb

24 lines
480 B
Ruby
Raw Normal View History

# frozen_string_literal: true
class DeletePreviewCardService < BaseService
include Redisable
def call(preview_card)
return if preview_card.nil?
@preview_card = preview_card
RedisLock.acquire(lock_options) do |lock|
if lock.acquired?
@preview_card.destroy!
else
raise GabSocial::RaceConditionError
end
end
end
def lock_options
{ redis: Redis.current, key: "distribute_preview_card:#{@preview_card.id}" }
end
end