Class: WatchQueryTask

Inherits:
Task
  • Object
show all
Defined in:
lib/engine/app/models/watch_query_task.rb

Constant Summary

Constants inherited from Task

Task::ACTIVE, Task::DEFAULT_DATABASE, Task::DEFAULT_INTERVAL, Task::INACTIVE

Instance Method Summary collapse

Methods inherited from Task

#active?, #backend, #init, #reset_queue, selectable_actions, #to_partial_path

Instance Method Details

#notify(old_value, new_value) ⇒ Object



20
21
22
23
# File 'lib/engine/app/models/watch_query_task.rb', line 20

def notify(old_value, new_value)
  msg = "Value of key '#{trigger}' has changed from #{old_value.inspect} to #{new_value.inspect}"
  Notification.create!(reporter: name, message: msg)
end

#performObject



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/engine/app/models/watch_query_task.rb', line 8

def perform
  result = SearchKeys.new(backend, trigger).result.map(&:with_indifferent_access)
  if data[:initialized]
    notify(data[:old_value], result) if data[:old_value] != result
  else
    data[:initialized] = true
  end

  data[:old_value] = result
  save
end

#type_nameObject



4
5
6
# File 'lib/engine/app/models/watch_query_task.rb', line 4

def type_name
  'Watch query'
end