Class: UINotifications::RemoteExecutionJobs::BaseJobFinish

Inherits:
Base
  • Object
show all
Defined in:
app/services/ui_notifications/remote_execution_jobs/base_job_finish.rb

Instance Method Summary collapse

Constructor Details

#initialize(job_invocation) ⇒ BaseJobFinish

Returns a new instance of BaseJobFinish.



4
5
6
# File 'app/services/ui_notifications/remote_execution_jobs/base_job_finish.rb', line 4

def initialize(job_invocation)
  @subject = job_invocation
end

Instance Method Details

#blueprintObject



22
23
24
25
# File 'app/services/ui_notifications/remote_execution_jobs/base_job_finish.rb', line 22

def blueprint
  blueprint = @subject.status == HostStatus::ExecutionStatus::ERROR ? 'rex_job_failed' : 'rex_job_succeeded'
  @blueprint ||= NotificationBlueprint.unscoped.find_by(:name => blueprint)
end

#deliver!Object



8
9
10
11
12
13
14
15
16
# File 'app/services/ui_notifications/remote_execution_jobs/base_job_finish.rb', line 8

def deliver!
  ::Notification.create!(
    :audience => Notification::AUDIENCE_USER,
    :notification_blueprint => blueprint,
    :initiator => initiator,
    :message => message,
    :subject => subject
  )
end

#initiatorObject



18
19
20
# File 'app/services/ui_notifications/remote_execution_jobs/base_job_finish.rb', line 18

def initiator
  User.anonymous_admin
end

#messageObject



27
28
29
# File 'app/services/ui_notifications/remote_execution_jobs/base_job_finish.rb', line 27

def message
  UINotifications::StringParser.new(blueprint.message, { subject: subject })
end