module Triglav::Agent::Base::Worker
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
Public Class Methods
new()
click to toggle source
serverengine interface
# File lib/triglav/agent/base/worker.rb, line 14 def initialize @timer = Timer.new reload_status end
Public Instance Methods
process()
click to toggle source
# 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
reload()
click to toggle source
serverengine interface
# File lib/triglav/agent/base/worker.rb, line 20 def reload $logger.info { "Worker#reload" } $setting.reload reload_status end
run()
click to toggle source
serverengine interface
# 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
start()
click to toggle source
# File lib/triglav/agent/base/worker.rb, line 58 def start @timer.start @stop = false end
stop()
click to toggle source
serverengine interface
# File lib/triglav/agent/base/worker.rb, line 64 def stop $logger.info { "Worker#stop" } @stop = true @timer.stop end
stopped?()
click to toggle source
# File lib/triglav/agent/base/worker.rb, line 70 def stopped? @stop end
Private Instance Methods
log_error(e)
click to toggle source
# File lib/triglav/agent/base/worker.rb, line 88 def log_error(e) $logger.error { "#{e.class} #{e.message} #{e.backtrace.join("\\n")}" } # one line end
monitor_interval()
click to toggle source
# File lib/triglav/agent/base/worker.rb, line 92 def monitor_interval $setting.dig(name, :monitor_interval) || 60 end
name()
click to toggle source
# File lib/triglav/agent/base/worker.rb, line 84 def name Configuration.name end
processor_class()
click to toggle source
# File lib/triglav/agent/base/worker.rb, line 80 def processor_class Configuration.processor_class end
reload_status()
click to toggle source
# File lib/triglav/agent/base/worker.rb, line 76 def reload_status Triglav::Agent::Status.select_resource_uri_prefixes!(resource_uri_prefixes) end
resource_uri_prefixes()
click to toggle source
# File lib/triglav/agent/base/worker.rb, line 96 def resource_uri_prefixes $setting.dig(name, :connection_info).keys end