Class: Coatepec::WorkerManager

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

Overview

Owns the single warm Worker::Client for a project: lazily starts it, restarts it when ChangeDetector flags a boot-file change, escalates a Gemfile change to :sidecar_restart_required, and retries a request once if the worker had died since the last dispatch.

Instance Method Summary collapse

Constructor Details

#initialize(project) ⇒ WorkerManager

Returns a new instance of WorkerManager.



11
12
13
14
15
16
17
# File 'lib/coatepec/worker_manager.rb', line 11

def initialize(project)
  @project = project
  @change_detector = Worker::ChangeDetector.new(project.root)
  @client = nil
  @snapshot = nil
  @lock = Monitor.new
end

Instance Method Details

#model(name:) ⇒ Object



35
36
37
# File 'lib/coatepec/worker_manager.rb', line 35

def model(name:)
  dispatch("model", { name: name }, timeout: 30)
end

#routes(query: nil, limit: 50, offset: 0) ⇒ Object



31
32
33
# File 'lib/coatepec/worker_manager.rb', line 31

def routes(query: nil, limit: 50, offset: 0)
  dispatch("routes", { query: query, limit: limit, offset: offset }, timeout: 30)
end

#run_spec(paths:, example:, seed:, fail_fast:, timeout_seconds:) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/coatepec/worker_manager.rb', line 23

def run_spec(paths:, example:, seed:, fail_fast:, timeout_seconds:)
  dispatch(
    "spec_run",
    { paths: paths, example: example, seed: seed, fail_fast: fail_fast, timeout_seconds: timeout_seconds },
    timeout: timeout_seconds + 10
  )
end

#statusObject



19
20
21
# File 'lib/coatepec/worker_manager.rb', line 19

def status
  dispatch("status", {}, timeout: 30)
end

#stopObject



39
40
41
# File 'lib/coatepec/worker_manager.rb', line 39

def stop
  @lock.synchronize { @client&.stop }
end