Sha256: 4a29b1c0e22571cb3a4da6ffba4df1cce9d2a4b503eb46b01b419315b896d81b

Contents?: true

Size: 1.66 KB

Versions: 1

Compression:

Stored size: 1.66 KB

Contents

module Katello
  module UINotifications
    module Pulp
      class ProxyDiskSpace
        class << self
          def deliver!
            SmartProxy.unscoped.with_content.each do |proxy|
              percentage = proxy.statuses[:pulp].storage['pulp_dir']['percent']
              if percentage[0..2].to_i < 90 && notification_already_exists?(proxy)
                blueprint.notifications.where(subject: proxy).destroy_all
                next
              end
              next unless update_notifications(proxy).empty?
              ::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

          def notification_already_exists?(subject)
            low_disk_notification = Notification.unscoped.find_by(:subject => subject)
            return false if low_disk_notification.blank?
            low_disk_notification.notification_blueprint == blueprint
          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

1 entries across 1 versions & 1 rubygems

Version Path
katello-3.7.0.rc1 app/services/katello/ui_notifications/pulp/proxy_disk_space.rb