Skip to content

Commit

Permalink
Add cusotm New Relic instrumentation
Browse files Browse the repository at this point in the history
  • Loading branch information
rwdaigle committed Oct 8, 2012
1 parent a33216b commit 63bd8e8
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Procfile
@@ -1,3 +1,3 @@
web: bundle exec thin start -p $PORT
worker: bundle exec rake qc:work
worker: bundle exec rake gisted:work
kanshi: bundle exec kanshi
4 changes: 0 additions & 4 deletions app/models/gist_fetcher.rb
Expand Up @@ -2,8 +2,6 @@ class GistFetcher

class << self

include ::NewRelic::Agent::Instrumentation::ControllerInstrumentation

def fetch
period = ENV['FETCH_INTERVAL_MINS'] ? ENV['FETCH_INTERVAL_MINS'].to_i : 1440
since = period.minutes.ago
Expand All @@ -24,8 +22,6 @@ def fetch_user(user_id)
end
user.update_attribute(:last_gh_fetch, Time.now)
end

add_transaction_tracer :fetch_user, :category => :task, :params => '{ :user_id => args[0] }'

protected

Expand Down
18 changes: 18 additions & 0 deletions app/models/gisted_worker.rb
@@ -0,0 +1,18 @@
require "queue_classic"

class GistedWorker < QC::Worker

include ::NewRelic::Agent::Instrumentation::ControllerInstrumentation
add_transaction_tracer :call, :category => :task, :params => '{ :job => args[0][:method], :args => args[0][:args] }'

# # retry the job
# def handle_failure(job, exception)
# @queue.enqueue(job[:method], *job[:args])
# end

# # the forked proc needs a new db connection
# def setup_child
# ActiveRecord::Base.establish_connection
# end

end
2 changes: 1 addition & 1 deletion lib/tasks/fetch.rake
@@ -1,7 +1,7 @@
namespace :fetch do

task :periodic => :environment do
GistFetcher.fetch
QC.enqueue("GistFetcher.fetch")
end

end
6 changes: 6 additions & 0 deletions lib/tasks/gisted.rake
@@ -0,0 +1,6 @@
namespace :gisted do

task :work => :environment do
GistedWorker.new.start
end
end

0 comments on commit 63bd8e8

Please sign in to comment.