# frozen_string_literal: true class ActivityPub::ProcessCollectionItemsService < BaseService def call(account_id, on_behalf_of) RedisLock.acquire(lock_options(account_id)) do |lock| if lock.acquired? CollectionItem.unprocessed.where(account_id: account_id).find_each do |item| begin FetchRemoteStatusService.new.call(item.uri, nil, on_behalf_of) rescue ActiveRecord::RecordInvalid, ActiveRecord::RecordNotFound nil end item.update!(processed: true) end end end end private def lock_options(account_id) { redis: Redis.current, key: "process_collection_items:#{account_id}" } end end