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



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

def initialize
  @timer = Timer.new
end

#processObject



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

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

  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 worker_id:#{worker_id} " \
    "success_count/total_count:#{total_success_count}/#{total_count} elapsed:#{elapsed.to_f}sec"
  }
end

#reloadObject

serverengine interface



18
19
20
21
# File 'lib/triglav/agent/base/worker.rb', line 18

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

#runObject

serverengine interface



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/triglav/agent/base/worker.rb', line 24

def run
  $logger.info { "Worker#run worker_id:#{worker_id}" }
  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



56
57
58
59
# File 'lib/triglav/agent/base/worker.rb', line 56

def start
  @timer.start
  @stop = false
end

#stopObject

serverengine interface



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

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

#stopped?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/triglav/agent/base/worker.rb', line 68

def stopped?
  @stop
end