Class: WatchKeyTask

Inherits:
Task
  • Object
show all
Defined in:
lib/engine/app/models/watch_key_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



18
19
20
21
# File 'lib/engine/app/models/watch_key_task.rb', line 18

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



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/engine/app/models/watch_key_task.rb', line 6

def perform
  result = RetrieveKey.new(backend, trigger).result
  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



2
3
4
# File 'lib/engine/app/models/watch_key_task.rb', line 2

def type_name
  'Watch key'
end