Skip to content

Commit

Permalink
don't log activejob timings
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Dec 20, 2019
1 parent dd0e3b8 commit 419b945
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ group :test do
gem 'rack-test', '~> 1.1', :require => "rack/test"
gem 'simplecov', '~> 0.1'
gem 'codeclimate-test-reporter', '~> 1.0', '>= 1.0.8'
gem "shoulda-matchers", "~> 2.7.0", :require => false
gem 'shoulda-matchers', '~> 4.1', '>= 4.1.2'
gem 'webmock', '~> 3.7'
gem 'vcr', '~> 3.0', '>= 3.0.3'
gem 'poltergeist', '~> 1.15'
Expand Down
12 changes: 6 additions & 6 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ GEM
arel (9.0.0)
ast (2.4.0)
aws-eventstream (1.0.3)
aws-partitions (1.257.0)
aws-partitions (1.258.0)
aws-sdk-core (3.86.0)
aws-eventstream (~> 1.0, >= 1.0.2)
aws-partitions (~> 1, >= 1.239.0)
Expand All @@ -74,7 +74,7 @@ GEM
aws-sdk-kms (1.27.0)
aws-sdk-core (~> 3, >= 3.71.0)
aws-sigv4 (~> 1.1)
aws-sdk-s3 (1.60.0)
aws-sdk-s3 (1.60.1)
aws-sdk-core (~> 3, >= 3.83.0)
aws-sdk-kms (~> 1)
aws-sigv4 (~> 1.1)
Expand Down Expand Up @@ -536,7 +536,7 @@ GEM
redis (4.1.3)
regexp_parser (1.6.0)
remotipart (1.4.3)
request_store (1.4.1)
request_store (1.5.0)
rack (>= 1.4)
responders (3.0.0)
actionpack (>= 5.0)
Expand Down Expand Up @@ -584,8 +584,8 @@ GEM
aws-sdk-core (>= 2)
concurrent-ruby
thor
shoulda-matchers (2.7.0)
activesupport (>= 3.0.0)
shoulda-matchers (4.1.2)
activesupport (>= 4.2.0)
simple_form (4.1.0)
actionpack (>= 5.0)
activemodel (>= 5.0)
Expand Down Expand Up @@ -745,7 +745,7 @@ DEPENDENCIES
rubocop-rails (~> 2.4)
sentry-raven (~> 2.9)
shoryuken (~> 4.0)
shoulda-matchers (~> 2.7.0)
shoulda-matchers (~> 4.1, >= 4.1.2)
simple_form (~> 4.1.0)
simplecov (~> 0.1)
spring
Expand Down
20 changes: 11 additions & 9 deletions app/models/claim.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ class Claim < ActiveRecord::Base

alias_attribute :state, :aasm_state

aasm :whiny_transitions => false do
aasm whiny_transitions: false do
# waiting is initial state for new claims
state :waiting, :initial => true
state :waiting, initial: true
state :working, :failed, :done, :ignored, :deleted, :notified

event :start do
Expand Down Expand Up @@ -148,7 +148,7 @@ def as_indexed_json(options={})
"claimed" => claimed,
"created" => created,
"updated" => updated,
"user" => user
"user" => user,
}
end

Expand Down Expand Up @@ -182,16 +182,18 @@ def to_param # overridden, use uuid instead of id
uuid
end

def process_data(options={})
def process_data(options = {})
self.start

### depdency Injection for testing
result = options[:collect_data] || collect_data

if result.body["skip"]
claimed_at.present? ? self.finish : self.skip
self.finish! && return if claimed_at.present?

logger.info "[Skipped] #{self.uid}#{self.doi}] #{result.body["reason"]}"
logger.info "[Skipped] #{self.uid}#{self.doi}] #{result.body['reason']}"

self.skip
elsif result.body["errors"]
write_attribute(:error_messages, result.body["errors"].inspect)

Expand Down Expand Up @@ -232,7 +234,7 @@ def collect_data(options={})
return OpenStruct.new(body: { "skip" => true, "Reason" => "already claimed." }) if to_be_created? && claimed_at.present?

# user has not signed up yet or orcid_token is missing
unless (user.present? && orcid_token.present?)
if (user.blank? || orcid_token.blank?)
if ENV['NOTIFICATION_ACCESS_TOKEN'].present?
response = notification.create_notification(options)
response.body["notification"] = true
Expand All @@ -254,7 +256,7 @@ def collect_data(options={})
# validate data
return OpenStruct.new(body: { "errors" => work.validation_errors.map { |error| { "title" => error } }}) if work.validation_errors.present?

options[:sandbox] = (ENV['ORCID_URL'] == "https://sandbox.orcid.org")
options[:sandbox] = (ENV["ORCID_URL"] == "https://sandbox.orcid.org")

# create or delete entry in ORCID record
if to_be_created?
Expand All @@ -277,7 +279,7 @@ def notification
end

def without_control(s)
r = ''
r = ""
s.each_codepoint do |c|
if c >= 32
r << c
Expand Down
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ def process_data(options={})
logger.info "Added Github username to ORCID record for user #{orcid}."
end

def push_github_identifier(options={})
def push_github_identifier(options = {})
# user has not linked github username
return OpenStruct.new(body: { "skip" => true }) unless github_to_be_created? || github_to_be_deleted?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
config.lograge.logger = LogStashLogger.new(type: :stdout)
config.lograge.log_level = ENV["LOG_LEVEL"].to_sym

config.active_job.logger = config.logger
config.active_job.logger = config.lograge.logger

config.lograge.ignore_actions = ["HeartbeatController#index", "IndexController#index"]
config.lograge.ignore_custom = lambda do |event|
Expand Down
24 changes: 22 additions & 2 deletions config/initializers/_shoryuken.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,28 @@
# frozen_string_literal: true

# Shoryuken middleware to capture worker errors and send them on to Sentry.io
module Shoryuken
module Middleware
module Server
class RavenReporter
def call(worker_instance, queue, sqs_msg, body)
tags = { job: body['job_class'], queue: queue }
context = { message: body }
Raven.capture(tags: tags, extra: context) do
yield
end
end
end
end
end
end

Shoryuken.configure_server do |config|
Rails.logger = Shoryuken::Logging.logger
Rails.logger.level = Logger.const_get(ENV["LOG_LEVEL"].upcase)
config.server_middleware do |chain|
# remove logging of timing events
chain.remove Shoryuken::Middleware::Server::Timing
chain.add Shoryuken::Middleware::Server::RavenReporter
end
end

Shoryuken.active_job_queue_name_prefixing = true

0 comments on commit 419b945

Please sign in to comment.