Sha256: 432f6f0793b840eef9a0505b94811b3a532cd386c3edea08bdd65039b9ddaf9d

Contents?: true

Size: 1.21 KB

Versions: 129

Compression:

Stored size: 1.21 KB

Contents

module Webhooks::Outgoing::TeamSupport
  extend ActiveSupport::Concern

  included do
    has_many :webhooks_outgoing_endpoints, class_name: "Webhooks::Outgoing::Endpoint", dependent: :destroy
    has_many :webhooks_outgoing_events, class_name: "Webhooks::Outgoing::Event", dependent: :destroy

    before_destroy :mark_for_destruction, prepend: true
  end

  def should_cache_endpoints_listening_for_event_type?
    true
  end

  def endpoint_api_versions_for_event_type(event_type)
    webhooks_outgoing_endpoints.listening_for_event_type_id(event_type.id).pluck(:api_version).uniq
  end

  def endpoint_api_versions_listening_for_event_type(event_type)
    if should_cache_endpoints_listening_for_event_type?
      key = "#{cache_key_with_version}/endpoints_for_event_type/#{event_type.cache_key}/api_version"

      Rails.cache.fetch(key, expires_in: 24.hours, race_condition_ttl: 5.seconds) do
        endpoint_api_versions_for_event_type(event_type)
      end
    else
      endpoint_api_versions_for_event_type(event_type)
    end
  end

  def mark_for_destruction
    # This allows downstream logic to check whether a team is being destroyed in order to bypass webhook issuance.
    update_column(:being_destroyed, true)
  end
end

Version data entries

129 entries across 129 versions & 1 rubygems

Version Path
bullet_train-outgoing_webhooks-1.10.0 app/models/concerns/webhooks/outgoing/team_support.rb
bullet_train-outgoing_webhooks-1.9.0 app/models/concerns/webhooks/outgoing/team_support.rb
bullet_train-outgoing_webhooks-1.8.5 app/models/concerns/webhooks/outgoing/team_support.rb
bullet_train-outgoing_webhooks-1.8.4 app/models/concerns/webhooks/outgoing/team_support.rb
bullet_train-outgoing_webhooks-1.8.3 app/models/concerns/webhooks/outgoing/team_support.rb
bullet_train-outgoing_webhooks-1.8.2 app/models/concerns/webhooks/outgoing/team_support.rb
bullet_train-outgoing_webhooks-1.8.1 app/models/concerns/webhooks/outgoing/team_support.rb
bullet_train-outgoing_webhooks-1.8.0 app/models/concerns/webhooks/outgoing/team_support.rb
bullet_train-outgoing_webhooks-1.7.23 app/models/concerns/webhooks/outgoing/team_support.rb
bullet_train-outgoing_webhooks-1.7.22 app/models/concerns/webhooks/outgoing/team_support.rb
bullet_train-outgoing_webhooks-1.7.21 app/models/concerns/webhooks/outgoing/team_support.rb
bullet_train-outgoing_webhooks-1.7.20 app/models/concerns/webhooks/outgoing/team_support.rb
bullet_train-outgoing_webhooks-1.7.19 app/models/concerns/webhooks/outgoing/team_support.rb
bullet_train-outgoing_webhooks-1.7.18 app/models/concerns/webhooks/outgoing/team_support.rb
bullet_train-outgoing_webhooks-1.7.17 app/models/concerns/webhooks/outgoing/team_support.rb
bullet_train-outgoing_webhooks-1.7.16 app/models/concerns/webhooks/outgoing/team_support.rb
bullet_train-outgoing_webhooks-1.7.15 app/models/concerns/webhooks/outgoing/team_support.rb
bullet_train-outgoing_webhooks-1.7.14 app/models/concerns/webhooks/outgoing/team_support.rb
bullet_train-outgoing_webhooks-1.7.13 app/models/concerns/webhooks/outgoing/team_support.rb
bullet_train-outgoing_webhooks-1.7.12 app/models/concerns/webhooks/outgoing/team_support.rb