Module: Triglav::Agent::Base::Worker

Defined in:
lib/triglav/agent/base/worker.rb

Overview

Triglav agent worker module for Serverengine.

You usually do not need to customize this module, but if you want to implement your original, configure

Triglav::Agent::Configuration.worker_module

Instance Method Summary collapse

Instance Method Details

#initializeObject

serverengine interface



14
15
16
17
# File 'lib/triglav/agent/base/worker.rb', line 14

def initialize
  @timer = Timer.new
  reload_status
end

#processObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/triglav/agent/base/worker.rb', line 39

def process
  started = Time.now
  $logger.info { "Start Worker#process" }

  total_count = 0
  total_success_count = 0
  resource_uri_prefixes.each do |resource_uri_prefix|
    break if stopped?
    processor = processor_class.new(self, resource_uri_prefix)
    total_count += processor.total_count
    total_success_count += processor.process
  end

  elapsed = Time.now - started
  $logger.info {
    "Finish Worker#process success_count/total_count:#{total_success_count}/#{total_count} elapsed:#{elapsed.to_f}sec"
  }
end

#reloadObject

serverengine interface



20
21
22
23
24
# File 'lib/triglav/agent/base/worker.rb', line 20

def reload
  $logger.info { "Worker#reload" }
  $setting.reload
  reload_status
end

#runObject

serverengine interface



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/triglav/agent/base/worker.rb', line 27

def run
  $logger.info { "Worker#run" }
  start
  until @stop
    @timer.wait(monitor_interval) { process }
  end
rescue => e
  # ServerEngine.dump_uncaught_error does not tell me e.class
  log_error(e)
  raise e
end

#startObject



58
59
60
61
# File 'lib/triglav/agent/base/worker.rb', line 58

def start
  @timer.start
  @stop = false
end

#stopObject

serverengine interface



64
65
66
67
68
# File 'lib/triglav/agent/base/worker.rb', line 64

def stop
  $logger.info { "Worker#stop" }
  @stop = true
  @timer.stop
end

#stopped?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/triglav/agent/base/worker.rb', line 70

def stopped?
  @stop
end