Sha256: ee3c50a99c98d357951fa684f849c46b8b5f2467a3f494caa55169c12e44f052

Contents?: true

Size: 1.62 KB

Versions: 89

Compression:

Stored size: 1.62 KB

Contents

module Katello
  module UINotifications
    module Pulp
      class ProxyDiskSpace
        class << self
          def deliver!
            SmartProxy.unscoped.with_content.each do |proxy|
              status = proxy.statuses[:pulp] || proxy.statuses[:pulpnode]
              next unless (percentage = status&.storage&.dig('pulp_dir', 'percent'))

              if percentage[0..2].to_i < 90 && notification_already_exists?(proxy)
                blueprint.notifications.where(subject: proxy).destroy_all
              elsif update_notifications(proxy).empty? && percentage[0..2].to_i > 90
                ::Notification.create!(
                  :subject => proxy,
                  :initiator => User.anonymous_admin,
                  :audience => Notification::AUDIENCE_ADMIN,
                  :message => ::UINotifications::StringParser.new(
                    blueprint.message,
                    :subject => proxy,
                    :percentage => percentage
                  ),
                  :notification_blueprint => blueprint
                )
              end
            end
          end

          def notification_already_exists?(subject)
            blueprint.notifications.where(:subject => subject).any?
          end

          def update_notifications(subject)
            notifs = blueprint.notifications
            notifs.where(subject: subject).update_all(expired_at: blueprint.expired_at)
            notifs
          end

          def blueprint
            @blueprint ||= NotificationBlueprint.unscoped.find_by(
              :name => 'pulp_low_disk_space')
          end
        end
      end
    end
  end
end

Version data entries

89 entries across 89 versions & 1 rubygems

Version Path
katello-3.18.5 app/services/katello/ui_notifications/pulp/proxy_disk_space.rb
katello-3.18.4 app/services/katello/ui_notifications/pulp/proxy_disk_space.rb
katello-3.18.3.1 app/services/katello/ui_notifications/pulp/proxy_disk_space.rb
katello-3.18.3 app/services/katello/ui_notifications/pulp/proxy_disk_space.rb
katello-3.18.2.1 app/services/katello/ui_notifications/pulp/proxy_disk_space.rb
katello-3.18.2 app/services/katello/ui_notifications/pulp/proxy_disk_space.rb
katello-3.17.3 app/services/katello/ui_notifications/pulp/proxy_disk_space.rb
katello-4.0.0.rc2 app/services/katello/ui_notifications/pulp/proxy_disk_space.rb
katello-3.18.1.1 app/services/katello/ui_notifications/pulp/proxy_disk_space.rb
katello-3.17.2 app/services/katello/ui_notifications/pulp/proxy_disk_space.rb
katello-4.0.0.rc1 app/services/katello/ui_notifications/pulp/proxy_disk_space.rb
katello-3.18.1 app/services/katello/ui_notifications/pulp/proxy_disk_space.rb
katello-3.18.0 app/services/katello/ui_notifications/pulp/proxy_disk_space.rb
katello-3.17.1 app/services/katello/ui_notifications/pulp/proxy_disk_space.rb
katello-3.16.2 app/services/katello/ui_notifications/pulp/proxy_disk_space.rb
katello-3.18.0.rc2.1 app/services/katello/ui_notifications/pulp/proxy_disk_space.rb
katello-3.18.0.rc2 app/services/katello/ui_notifications/pulp/proxy_disk_space.rb
katello-3.17.0 app/services/katello/ui_notifications/pulp/proxy_disk_space.rb
katello-3.18.0.rc1 app/services/katello/ui_notifications/pulp/proxy_disk_space.rb
katello-3.17.0.rc2.2 app/services/katello/ui_notifications/pulp/proxy_disk_space.rb