Question: how to inject data into puma worker

Question

how to inject data into puma worker

Answers 0
Added at 2016-12-13 22:12
Tags
Question

I'm using Puma in clustered mode, and I'd like to inject some configuration data stored outside the Puma configuration file into my workers. Is this possible? Currently I have the following:

before_fork do
  puts "Starting workers..."
  @databases = YAML.load_file "database.yml"
  @tokens = YAML.load_file "token.yml"
end

on_worker_boot do
  puts "On worker boot..."
  require 'active_record'
  ActiveRecord::Base.establish_connection @databases[ENV["RACK_ENV"]]
end

I'd like to inject the value of @tokens into each worker, before it starts serving requests. I'm using Sinatra and Rack, if that's relevant.

Answers to

how to inject data into puma worker

Source Show
◀ Wstecz