Class: UINotifications::Tasks::TasksRunningLong

Inherits:
Base
  • Object
show all
Defined in:
app/services/ui_notifications/tasks/tasks_running_long.rb

Instance Method Summary collapse

Methods inherited from Base

#initialize, #initiator, #troubleshooting_help_generator

Constructor Details

This class inherits a constructor from UINotifications::Tasks::Base

Instance Method Details

#blueprintObject



24
25
26
# File 'app/services/ui_notifications/tasks/tasks_running_long.rb', line 24

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

#deliver!Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/services/ui_notifications/tasks/tasks_running_long.rb', line 6

def deliver!
  notification = ::Notification.new(
    :audience => Notification::AUDIENCE_GLOBAL,
    :notification_blueprint => blueprint,
    :initiator => initiator,
    :message => message,
    :subject => nil,
    :notification_recipients => [NotificationRecipient.create(:user => User.current)]
  )
  notification.actions['links'] ||= []
  notification.actions['links'] << {
    href: foreman_tasks_tasks_path(search: subject.query),
    title: N_('Long running tasks'),
  }
  notification.save!
  notification
end

#messageObject



28
29
30
# File 'app/services/ui_notifications/tasks/tasks_running_long.rb', line 28

def message
  _("%{count} tasks are in running or paused state for more than a day") % { count: subject.task_uuids.count }
end