Class: Wurk::Railtie

Inherits:
Rails::Railtie
  • Object
show all
Defined in:
lib/wurk/railtie.rb

Overview

Boot the swarm after the host app has fully initialized. Skip when: WURK_DISABLED=1, Rails console mode, or Rails test env. See docs/idea/03-process-model.md for the exact ordering.

Class Method Summary collapse

Class Method Details

.building?Boolean

A build/precompile step must never fork the swarm (#247). The default Rails Dockerfile runs ‘SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile`; that loads `:environment` → fires after_initialize, but there’s no Redis during ‘docker build`, so a fork would hang/fail the build. Same for other env-loading rake tasks (db:prepare, db:migrate). The real server path is unaffected: `rails server` / `puma` boot through Rails::Command, not Rake, and don’t set the dummy secret.

Returns:

  • (Boolean)


52
53
54
55
56
57
58
# File 'lib/wurk/railtie.rb', line 52

def self.building?
  return true if ENV.key?('SECRET_KEY_BASE_DUMMY')

  defined?(::Rake) && ::Rake.application.top_level_tasks.any?
rescue StandardError
  false
end

.skip_boot?Boolean

A process that won’t run workers isn’t a server: skip both server mode and the swarm boot. Console mode is detected reliably here — the console command file defines ::Rails::Console before initializers run.

Returns:

  • (Boolean)


38
39
40
41
42
43
# File 'lib/wurk/railtie.rb', line 38

def self.skip_boot?
  ENV['WURK_DISABLED'] == '1' ||
    building? ||
    defined?(::Rails::Console) ||
    ::Rails.env.test?
end