Skip to content

Commit

Permalink
Improve reliability of AppSignal initialization process
Browse files Browse the repository at this point in the history
Since Puma detects running threads when preloading an application we need
to stop it and then restart when each of the workers are forked. It was
sort of working before because it detected when the PID of the process had
changed and then restarted the thread itself.
  • Loading branch information
pixeltrix committed Jul 31, 2015
1 parent 7fcd15a commit 6caec23
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions bin/delayed_job
Expand Up @@ -3,4 +3,7 @@
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'config', 'environment'))
require 'delayed/command'

# Restart the AppSignal thread that we stopped in the initializer
Appsignal.agent.start_thread if defined?(Appsignal) && Appsignal.config.active?

Delayed::Command.new(ARGV).daemonize
2 changes: 2 additions & 0 deletions config/initializers/appsignal.rb
@@ -0,0 +1,2 @@
# Stop the AppSignal agent thread and restart it when the workers are forked
Appsignal.agent.stop_thread if defined?(Appsignal) && Appsignal.config.active?
3 changes: 3 additions & 0 deletions config/puma.rb
Expand Up @@ -24,4 +24,7 @@
# Worker specific setup for Rails 4.1+
# See: https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server#on-worker-boot
ActiveRecord::Base.establish_connection

# Let AppSignal know that a worker process has been forked
Appsignal.agent.forked! if defined?(Appsignal) && Appsignal.config.active?
end

0 comments on commit 6caec23

Please sign in to comment.