Class: OsCtld::HintUpdater
- Inherits:
-
Object
- Object
- OsCtld::HintUpdater
- Includes:
- OsCtl::Lib::Utils::Exception, OsCtl::Lib::Utils::Log
- Defined in:
- lib/osctld/hint_updater.rb
Overview
Update container hints at regular intervals
Instance Method Summary collapse
-
#initialize(pool) ⇒ HintUpdater
constructor
A new instance of HintUpdater.
- #log_type ⇒ Object
- #run_ct_updates ⇒ Object protected
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(pool) ⇒ HintUpdater
Returns a new instance of HintUpdater.
10 11 12 13 |
# File 'lib/osctld/hint_updater.rb', line 10 def initialize(pool) @pool = pool @ct_queue = OsCtl::Lib::Queue.new end |
Instance Method Details
#log_type ⇒ Object
32 33 34 |
# File 'lib/osctld/hint_updater.rb', line 32 def log_type @pool.name end |
#run_ct_updates ⇒ Object (protected)
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/osctld/hint_updater.rb', line 38 def run_ct_updates loop do v = @ct_queue.pop(timeout: 8 * 60 * 60) return if v == :stop t1 = Time.now log(:info, 'Updating container hints') DB::Containers.get.each do |ct| break if @stop next if ct.pool != @pool || !ct.running? begin ct.update_hints rescue StandardError => e log(:warn, ct, "Unable to update hints: #{e.} (#{e.class})") log(:warn, ct, denixstorify(e.backtrace)) end sleep(0.2) end break if @stop log(:info, "Finished updating container hints in #{(Time.now - t1).round(2)}s") end end |
#start ⇒ Object
15 16 17 18 19 20 |
# File 'lib/osctld/hint_updater.rb', line 15 def start raise 'already started' if @ct_thread @stop = false @ct_thread = Thread.new { run_ct_updates } end |
#stop ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/osctld/hint_updater.rb', line 22 def stop return unless @ct_thread @stop = true @ct_queue.clear @ct_queue << :stop @ct_thread.join @ct_thread = nil end |