Class: Kabutops::Watchdog

Inherits:
Object
  • Object
show all
Extended by:
Extensions::CallbackSupport, Extensions::Parameterable
Includes:
Extensions::Logging, Sidekiq::Worker
Defined in:
lib/kabutops/watchdog.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Extensions::CallbackSupport

callbacks, manager, notify

Methods included from Extensions::Includable

#append_features, #included

Methods included from Extensions::Logging

#logger

Class Method Details

.checkObject



17
18
19
# File 'lib/kabutops/watchdog.rb', line 17

def check
  new.check
end

.check!Object



13
14
15
# File 'lib/kabutops/watchdog.rb', line 13

def check!
  perform_async
end

.loopObject



21
22
23
24
25
26
# File 'lib/kabutops/watchdog.rb', line 21

def loop
  loop do
    sleep self.params[:wait] || 5
    check
  end
end

Instance Method Details

#checkObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/kabutops/watchdog.rb', line 29

def check
  logger.info "#{self.class} check started"

  outdated_resources.each do |resource|
    resource.update(scheduled_update_at: Time.now.to_i)

    adapters.each do |adapter|
      adapter.store(resource)
    end

    self.class.notify(:on_outdated, resource)
  end

  logger.info "#{self.class} check finished"
end

#performObject



45
46
47
48
49
# File 'lib/kabutops/watchdog.rb', line 45

def perform
  check
  sleep self.class.params[:wait] || 5
  self.class.perform_async
end