opener-daemons 2.2.2 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8541a83a5ab552b4bd656f4622d7f325072778b8
4
- data.tar.gz: 93fc204fba7c1f4c9dcf2c80e7c9697bf87529b2
3
+ metadata.gz: d343e353902637e8107d0fae767b78ae6f1d5088
4
+ data.tar.gz: ca6e691a8224d1d8b9fdc10e1fa60b688f4e13c3
5
5
  SHA512:
6
- metadata.gz: f7afbad52756a4e51e17e2f31c5e79d4288e8498632d0f844fbf7d0d9a7b084e515083754652974633a17a681d88d4a19ea5a9f098b3dfe479d8117b04c34fe1
7
- data.tar.gz: 4974100fc4211e97fa4f4cd53c8a2718097c481f7b8e0b2277e716b184f56add575e02e918874257f5a76514085415d1048d32bb9049472c1bfa7c321032e8f4
6
+ metadata.gz: c4e8da4cb952e4168d1e82dcb7c1a50e60558355618919ed33f0384ea8ebfe948701eb369367dde02fab5f1b5c6894a7de0994ed501bba516331e30978eaf228
7
+ data.tar.gz: c5b0205a179c591d1389c62696aae256e2973a6b446a91f5885aacef2229597384a3d4af095bad50ad01e3bee6e42cb3855dc377828da1b4af920d63788d10a4
@@ -75,9 +75,7 @@ module Opener
75
75
  # @param [StandardError] error
76
76
  #
77
77
  def error(error)
78
- error, params = unwrap_error(error)
79
-
80
- report_exception(error, params)
78
+ report_exception(error)
81
79
  end
82
80
 
83
81
  ##
@@ -89,39 +87,29 @@ module Opener
89
87
  log_msg = "Finished message #{message.id}"
90
88
 
91
89
  Core::Syslog.info(log_msg)
90
+
91
+ ensure
92
+ Transaction.reset_current
92
93
  end
93
94
 
94
95
  ##
95
96
  # Sends an error to Rollbar.
96
97
  #
97
98
  # @param [StandardError] error
98
- # @param [Hash] parameters
99
99
  #
100
- def report_exception(error, parameters = {})
100
+ def report_exception(error)
101
101
  if Daemons.rollbar?
102
102
  Rollbar.error(
103
103
  error,
104
104
  :active_threads => Thread.list.count,
105
105
  :ruby_description => RUBY_DESCRIPTION,
106
- :parameters => parameters
106
+ :parameters => Transaction.current.parameters
107
107
  )
108
108
  else
109
109
  raise error
110
110
  end
111
- end
112
-
113
- ##
114
- # Takes either a regular error or a `Oni::WrappedError` and unwraps it,
115
- # returning the original error and the parameters (if any).
116
- #
117
- # @param [StandardError] error
118
- # @return [Array]
119
- #
120
- def unwrap_error(error)
121
- params = error.respond_to?(:parameters) ? error.parameters : {}
122
- error = error.original_error if error.respond_to?(:original_error)
123
-
124
- return error, params
111
+ ensure
112
+ Transaction.reset_current
125
113
  end
126
114
  end # Daemon
127
115
  end # Daemons
@@ -0,0 +1,56 @@
1
+ module Opener
2
+ module Daemons
3
+ ##
4
+ # Class for storing information of a single transaction in a thread.
5
+ #
6
+ # @!attribute [r] parameters
7
+ # @return [Hash]
8
+ #
9
+ class Transaction
10
+ attr_reader :parameters
11
+
12
+ ##
13
+ # The name of the key to store the current transaction in.
14
+ #
15
+ # @return [Symbol]
16
+ #
17
+ THREAD_KEY = :opener_daemons_transaction
18
+
19
+ ##
20
+ # Returns the current transaction.
21
+ #
22
+ # @return [Opener::Daemons::Transaction]
23
+ #
24
+ def self.current
25
+ return Thread.current[THREAD_KEY] ||= new
26
+ end
27
+
28
+ ##
29
+ # Removes the current transaction
30
+ #
31
+ def self.reset_current
32
+ Thread.current[THREAD_KEY] = nil
33
+ end
34
+
35
+ def initialize
36
+ @parameters = {}
37
+ end
38
+
39
+ ##
40
+ # Merges the given parameters with the existing ones.
41
+ #
42
+ # If New Relic is enabled the parameters are also added to the current
43
+ # New Relic transaction.
44
+ #
45
+ # @param [Hash] parameters
46
+ #
47
+ def add_parameters(parameters = {})
48
+ @parameters = @parameters.merge(parameters)
49
+
50
+ if Daemons.newrelic?
51
+ NewRelic::Agent.add_custom_parameters(parameters)
52
+ end
53
+ end
54
+ end # Transaction
55
+ end # Daemons
56
+ end # Opener
@@ -1,5 +1,5 @@
1
1
  module Opener
2
2
  module Daemons
3
- VERSION = '2.2.2'
3
+ VERSION = '2.3.0'
4
4
  end # Daemons
5
5
  end # Opener
@@ -39,11 +39,11 @@ module Opener
39
39
  # @raise [Oni::WrappedError]
40
40
  #
41
41
  def process
42
- add_newrelic_attributes
42
+ add_transaction_attributes
43
43
 
44
- input = downloader.download(config.input_url)
45
- output = config.component_instance.run(input)
46
- object = uploader.upload(config.identifier, output, config.metadata)
44
+ input = downloader.download(config.input_url)
45
+ output = config.component_instance.run(input)
46
+ object = uploader.upload(config.identifier, output, config.metadata)
47
47
 
48
48
  Core::Syslog.info(
49
49
  "Wrote output to s3://#{Daemons.output_bucket}/#{object.key}",
@@ -51,14 +51,6 @@ module Opener
51
51
  )
52
52
 
53
53
  submit_callbacks(object)
54
-
55
- rescue Exception => error
56
- raise Oni::WrappedError.from(
57
- error,
58
- :input_url => config.input_url,
59
- :callbacks => config.callbacks,
60
- :metadata => config.metadata
61
- )
62
54
  end
63
55
 
64
56
  ##
@@ -84,14 +76,13 @@ module Opener
84
76
 
85
77
  private
86
78
 
87
- def add_newrelic_attributes
88
- if Daemons.newrelic?
89
- NewRelic::Agent.add_custom_parameters(
90
- :input_url => config.input_url,
91
- :callbacks => config.callbacks.join(', '),
92
- :metadata => config.metadata
93
- )
94
- end
79
+ def add_transaction_attributes
80
+ Transaction.current.add_parameters(
81
+ :input_url => config.input_url,
82
+ :identifier => config.identifier,
83
+ :callbacks => config.callbacks,
84
+ :metadata => config.metadata
85
+ )
95
86
  end
96
87
 
97
88
  if Daemons.newrelic?
@@ -20,6 +20,7 @@ require_relative 'daemons/pidfile'
20
20
  require_relative 'daemons/configuration'
21
21
  require_relative 'daemons/downloader'
22
22
  require_relative 'daemons/uploader'
23
+ require_relative 'daemons/transaction'
23
24
 
24
25
  require_relative 'daemons/mapper'
25
26
  require_relative 'daemons/worker'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opener-daemons
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.2
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wilco van Duinkerken
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-12-02 00:00:00.000000000 Z
12
+ date: 2014-12-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: aws-sdk
@@ -205,6 +205,7 @@ files:
205
205
  - lib/opener/daemons/mapper.rb
206
206
  - lib/opener/daemons/option_parser.rb
207
207
  - lib/opener/daemons/pidfile.rb
208
+ - lib/opener/daemons/transaction.rb
208
209
  - lib/opener/daemons/uploader.rb
209
210
  - lib/opener/daemons/version.rb
210
211
  - lib/opener/daemons/worker.rb