Class: Coatepec::Worker::ChangeDetector

Inherits:
Object
  • Object
show all
Defined in:
lib/coatepec/worker/change_detector.rb

Overview

Fingerprints Gemfile/Gemfile.lock and boot-relevant files (mtime + size) so WorkerManager can decide whether a bundle change requires the whole sidecar to restart, or a boot-file change just the worker.

Constant Summary collapse

BUNDLE_FILES =
%w[Gemfile Gemfile.lock].freeze
BOOT_FILES =
%w[config/boot.rb config/application.rb config/environment.rb config/environments/test.rb].freeze

Instance Method Summary collapse

Constructor Details

#initialize(project_root) ⇒ ChangeDetector

Returns a new instance of ChangeDetector.



12
13
14
# File 'lib/coatepec/worker/change_detector.rb', line 12

def initialize(project_root)
  @project_root = project_root
end

Instance Method Details

#restart_reason(previous_snapshot) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/coatepec/worker/change_detector.rb', line 20

def restart_reason(previous_snapshot)
  current = snapshot
  return :sidecar_restart_required if current[:bundle] != previous_snapshot[:bundle]
  return :worker_restart_required if current[:boot] != previous_snapshot[:boot]

  nil
end

#snapshotObject



16
17
18
# File 'lib/coatepec/worker/change_detector.rb', line 16

def snapshot
  { bundle: fingerprint(BUNDLE_FILES), boot: fingerprint(BOOT_FILES + initializer_files) }
end