Skip to content

Instantly share code, notes, and snippets.

@newrelic
Forked from malomalo/newrelic.rb
Created March 11, 2010 00:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save newrelic/328629 to your computer and use it in GitHub Desktop.
Save newrelic/328629 to your computer and use it in GitHub Desktop.
class Job
def self.perform_with_newrelic(*args)
NewRelic::Control.instance['forked_job'] = true
perform(*args)
NewRelic::Agent.shutdown
end
end
module NewRelic
module Agent
class Agent
def ensure_worker_thread_started
return unless control.agent_enabled? && control.monitor_mode? && !@invalid_license
if !running? && !control['forked_job']
# We got some reports of threading errors in Unicorn with this.
log.debug "Detected that the worker loop is not running. Restarting." rescue nil
# Assume we've been forked, clear out stats that are left over from parent process
reset_stats
launch_worker_thread
@stats_engine.spawn_sampler_thread
end
end
end
end
end
module Resque
class Job
def perform
args ? payload_class.perform_with_newrelic(*args) : payload_class.perform_with_newrelic
end
end
end
Resque.after_fork do |job|
ActiveRecord::Base.connection.reconnect!
end
task "resque:setup" => :environment do
NewRelic::Agent.manual_start :app_name => 'fc-staging'#ENV['APP_NAME']
end
desc "Alias for resque:work (To run workers on Heroku)"
task "jobs:work" => "resque:work"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment