Class: NurseAndrea::ContinuousScanner

Inherits:
Object
  • Object
show all
Defined in:
lib/nurse_andrea/continuous_scanner.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.threadObject (readonly)

Returns the value of attribute thread.



36
37
38
# File 'lib/nurse_andrea/continuous_scanner.rb', line 36

def thread
  @thread
end

Class Method Details

.rescan_safelyObject

Public so specs can call it without spinning the loop.



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/nurse_andrea/continuous_scanner.rb', line 63

def rescan_safely
  return if NurseAndrea::SelfFilter.platform_self?

  discoveries = NurseAndrea::ManagedServiceScanner.scan
  return if discoveries.empty?

  # Only push new items — ManagedServiceScanner already dedups
  # by (type, tech, provider) within a single call, so we just
  # need to avoid resubmitting items already queued for the
  # current flush.
  existing_keys = NurseAndrea.component_discoveries.map { |d| [ d[:type], d[:tech], d[:provider] ] }
  discoveries.reject! { |d| existing_keys.include?([ d[:type], d[:tech], d[:provider] ]) }
  NurseAndrea.component_discoveries.concat(discoveries) if discoveries.any?
rescue => e
  NurseAndrea.debug("[ContinuousScanner] error: #{e.class}: #{e.message}")
end

.running?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/nurse_andrea/continuous_scanner.rb', line 58

def running?
  @thread&.alive? == true
end

.start!Object



38
39
40
41
42
43
44
45
46
47
# File 'lib/nurse_andrea/continuous_scanner.rb', line 38

def start!
  @mutex.synchronize do
    return if @thread&.alive?
    return if NurseAndrea.config.disable_continuous_scan

    @stop   = false
    @thread = Thread.new { run_loop }
    @thread.name = "nurse_andrea_continuous_scanner"
  end
end

.stop!Object



49
50
51
52
53
54
55
56
# File 'lib/nurse_andrea/continuous_scanner.rb', line 49

def stop!
  @mutex.synchronize do
    @stop = true
  end
  @thread&.wakeup rescue nil
  @thread&.join(2)
  @thread = nil
end