Class: Ibex::Watch::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/ibex/watch/runner.rb

Overview

Polls source fingerprints, debounces changes, and publishes stable builds.

Constant Summary collapse

DEFAULT_INTERVAL =

: Float

0.25
DEFAULT_DEBOUNCE =

: Float

0.05

Instance Method Summary collapse

Constructor Details

#initialize(paths:, build:, publish:, failure_paths:, stderr:, clock:, sleeper:, iteration_hook:, interval: DEFAULT_INTERVAL, debounce: DEFAULT_DEBOUNCE) ⇒ Runner

rubocop:disable Layout/LineLength



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/ibex/watch/runner.rb', line 13

def initialize(paths:, build:, publish:, failure_paths:, stderr:, clock:, sleeper:, iteration_hook:,
               interval: DEFAULT_INTERVAL, debounce: DEFAULT_DEBOUNCE)
  @fixed_paths = normalize_paths(paths)
  @successful_paths = [] #: Array[String]
  @paths = @fixed_paths
  @build = build
  @publish = publish
  @failure_paths = failure_paths
  @stderr = stderr
  @clock = clock
  @sleeper = sleeper
  @iteration_hook = iteration_hook
  @interval = interval
  @debounce = debounce
  @signal_status = nil #: Integer?
  @requested_status = nil #: Integer?
  @last_failure_message = nil #: String?
  @last_failure_snapshot = nil #: SourceSnapshot?
  @iteration = 0
end

Instance Method Details

#runObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/ibex/watch/runner.rb', line 36

def run
  with_signal_handlers do
    snapshot = SourceSnapshot.new(@paths)
    loop do
      status = stop_status(:before_build)
      return status if status

      snapshot, retry_build = build_once(snapshot)
      status = stop_status(:after_build)
      return status if status

      if retry_build
        snapshot = debounce(snapshot)
        status = @signal_status || @requested_status
        return status if status

        next
      end

      snapshot = wait_for_change(snapshot)
      status = @signal_status || @requested_status
      return status if status
    end
  end
end