Class: Coatepec::Worker::RailsRuntime

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

Overview

Boots the fixture/target Rails app under RAILS_ENV=test exactly once per worker process and reports its identity (pid, boot_id, versions, lifecycle state) for rails_runtime_status.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project_root) ⇒ RailsRuntime

Returns a new instance of RailsRuntime.



13
14
15
16
# File 'lib/coatepec/worker/rails_runtime.rb', line 13

def initialize(project_root)
  @project_root = project_root
  @booted = false
end

Instance Attribute Details

#boot_duration_msObject (readonly)

Returns the value of attribute boot_duration_ms.



11
12
13
# File 'lib/coatepec/worker/rails_runtime.rb', line 11

def boot_duration_ms
  @boot_duration_ms
end

#boot_idObject (readonly)

Returns the value of attribute boot_id.



11
12
13
# File 'lib/coatepec/worker/rails_runtime.rb', line 11

def boot_id
  @boot_id
end

#pidObject (readonly)

Returns the value of attribute pid.



11
12
13
# File 'lib/coatepec/worker/rails_runtime.rb', line 11

def pid
  @pid
end

#post_boot_thread_countObject (readonly)

Returns the value of attribute post_boot_thread_count.



11
12
13
# File 'lib/coatepec/worker/rails_runtime.rb', line 11

def post_boot_thread_count
  @post_boot_thread_count
end

#rails_versionObject (readonly)

Returns the value of attribute rails_version.



11
12
13
# File 'lib/coatepec/worker/rails_runtime.rb', line 11

def rails_version
  @rails_version
end

#ruby_versionObject (readonly)

Returns the value of attribute ruby_version.



11
12
13
# File 'lib/coatepec/worker/rails_runtime.rb', line 11

def ruby_version
  @ruby_version
end

Instance Method Details

#boot!Object



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/coatepec/worker/rails_runtime.rb', line 22

def boot!
  started_at = Process.clock_gettime(Process::CLOCK_MONOTONIC)
  ENV["RAILS_ENV"] = "test"
  force_reloading!
  require File.join(@project_root, "config/environment")
  record_boot!(started_at)
rescue Coatepec::Error
  raise
rescue StandardError, LoadError => e
  raise Coatepec::Error.new(:worker_failure, "Rails failed to boot: #{e.message}")
end

#booted?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/coatepec/worker/rails_runtime.rb', line 18

def booted?
  @booted
end

#loaded_gem_namesObject

Loaded gem names for GuardedForkStrategy's denylist check. RailsRuntime itself has no notion of macOS or forking -- it only exposes the raw fact of what's loaded.



50
51
52
# File 'lib/coatepec/worker/rails_runtime.rb', line 50

def loaded_gem_names
  Gem.loaded_specs.keys.map(&:to_s)
end

#statusObject



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/coatepec/worker/rails_runtime.rb', line 34

def status
  {
    pid: pid,
    boot_id: boot_id,
    ruby_version: ruby_version,
    rails_version: rails_version,
    boot_duration_ms: boot_duration_ms,
    environment: "test",
    coatepec_version: Coatepec::VERSION,
    lifecycle_state: booted? ? "ready" : "not_started"
  }
end