Class: Katello::UINotifications::Pulp::ProxyDiskSpace

Inherits:
Object
  • Object
show all
Defined in:
app/services/katello/ui_notifications/pulp/proxy_disk_space.rb

Class Method Summary collapse

Class Method Details

.blueprintObject



37
38
39
40
# File 'app/services/katello/ui_notifications/pulp/proxy_disk_space.rb', line 37

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

.deliver!Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/services/katello/ui_notifications/pulp/proxy_disk_space.rb', line 6

def deliver!
  SmartProxy.unscoped.with_content.each do |proxy|
    percentage = proxy.pulp_disk_usage[0]['percentage']
    if percentage < 90 && notification_already_exists?(proxy)
      blueprint.notifications.where(subject: proxy).destroy_all
    elsif update_notifications(proxy).empty? && percentage > 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

.notification_already_exists?(subject) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
# File 'app/services/katello/ui_notifications/pulp/proxy_disk_space.rb', line 27

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

.update_notifications(subject) ⇒ Object



31
32
33
34
35
# File 'app/services/katello/ui_notifications/pulp/proxy_disk_space.rb', line 31

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