Class: Onair::Orchestrator

Inherits:
Object
  • Object
show all
Defined in:
lib/onair/orchestrator.rb

Overview

Runs the platform adapter and git concurrently, lazily fetches missing commits at most once, and assembles the Report.

Instance Method Summary collapse

Constructor Details

#initialize(config:, adapter:, git:, repo: nil) ⇒ Orchestrator

Returns a new instance of Orchestrator.



7
8
9
10
11
12
# File 'lib/onair/orchestrator.rb', line 7

def initialize(config:, adapter:, git:, repo: nil)
  @config = config
  @adapter = adapter
  @git = git
  @repo = repo
end

Instance Method Details

#runObject



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/onair/orchestrator.rb', line 14

def run
  snapshot_thread = quiet_thread { @adapter.snapshot }
  head_thread = quiet_thread { RemoteHead.resolve(git: @git, branch: @config.branch, repo: @repo) }
  snapshot = snapshot_thread.value
  remote_head = head_thread.value

  needed = [snapshot.deployed&.sha, snapshot.pending&.sha, remote_head].compact
  @git.fetch_once! if needed.any? { |sha| !@git.has_commit?(sha) }

  Report.build(snapshot: snapshot, remote_head: remote_head, git: @git)
end