Class: AlertExecution

Inherits:
Object
  • Object
show all
Defined in:
app/models/alert_execution.rb

Class Method Summary collapse

Class Method Details

.perform(alert_id, role) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/models/alert_execution.rb', line 4

def self.perform(alert_id, role)
  alert = Alert.find(alert_id)
  alert.status = Alert::STATUSES.pending
  alert.save!

  interaction = Interaction::ResultCreation.new(
    query_version_id: alert.latest_query_version.id,
    owner: alert.user
  )

  result = interaction.execute

  if interaction.errors.any?
    alert.error(interaction.errors.join(', '))
  else
    alert.last_alert_result = result
    alert.save!
    QueryExecution.perform(result.id, role)
    alert.check_last_result
  end
end