Welcome to mirror list, hosted at ThFree Co, Russian Federation.

releases_subscription_worker.rb « projects « activity_pub « workers « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c392726a4697c4a27b238287c31094920e236e61 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# frozen_string_literal: true

module ActivityPub
  module Projects
    class ReleasesSubscriptionWorker
      include ApplicationWorker
      include Gitlab::Routing.url_helpers

      idempotent!
      worker_has_external_dependencies!
      feature_category :release_orchestration
      data_consistency :delayed
      queue_namespace :activity_pub

      sidekiq_retries_exhausted do |msg, _ex|
        subscription_id = msg['args'].second
        subscription = ActivityPub::ReleasesSubscription.find_by_id(subscription_id)
        subscription&.destroy
      end

      def perform(subscription_id)
        subscription = ActivityPub::ReleasesSubscription.find_by_id(subscription_id)
        return if subscription.nil?

        unless subscription.project.public?
          subscription.destroy
          return
        end

        InboxResolverService.new(subscription).execute if needs_resolving?(subscription)
        AcceptFollowService.new(subscription, project_releases_url(subscription.project)).execute
      end

      def needs_resolving?(subscription)
        subscription.subscriber_inbox_url.blank? || subscription.shared_inbox_url.blank?
      end
    end
  end
end