background_lite 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/background_lite/background.rb +16 -2
  2. metadata +4 -4
@@ -1,5 +1,6 @@
1
1
  require 'digest/sha1'
2
2
  require 'logger'
3
+ require 'benchmark'
3
4
 
4
5
  # This module holds methods for background handling
5
6
  module BackgroundLite
@@ -17,9 +18,14 @@ module BackgroundLite
17
18
  @@default_error_reporter = :stdout
18
19
  cattr_accessor :default_error_reporter
19
20
 
20
- # Logger for debugging purposes
21
+ # Logger for debugging purposes.
21
22
  cattr_writer :default_logger
22
23
 
24
+ # Time in seconds a job may take before it is logged into slow log.
25
+ # Set to 0 for no logging.
26
+ @@slow_threshold = 0
27
+ cattr_accessor :slow_threshold
28
+
23
29
  def self.config #:nodoc:
24
30
  @config ||= YAML.load(File.read("#{RAILS_ROOT}/config/background.yml")) rescue { RAILS_ENV => {} }
25
31
  end
@@ -119,7 +125,14 @@ module BackgroundLite
119
125
  options[:transaction_id] = Digest::SHA1.hexdigest(object.to_s + method.to_s + args.inspect + Time.now.to_s)
120
126
  logger.debug("Sending to background: Object: #{object.inspect} Method: #{method} Args: #{args.inspect} Options: #{options.inspect}")
121
127
  end
122
- "BackgroundLite::#{hand.to_s.camelize}Handler".constantize.handle(object, method, args, options)
128
+
129
+ time = Benchmark.realtime do
130
+ "BackgroundLite::#{hand.to_s.camelize}Handler".constantize.handle(object, method, args, options)
131
+ end
132
+
133
+ if BackgroundLite::Config.slow_threshold > 0 && time > BackgroundLite::Config.slow_threshold
134
+ logger.fatal("Slow background job (#{time}s): #{object.class.name}##{method}(#{args.inspect}) on object #{object.inspect}")
135
+ end
123
136
  end
124
137
 
125
138
  return hand
@@ -127,5 +140,6 @@ module BackgroundLite
127
140
  "BackgroundLite::#{reporter.to_s.camelize}ErrorReporter".constantize.report(e)
128
141
  end
129
142
  end
143
+ return nil
130
144
  end
131
145
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: background_lite
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 31
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 3
10
- version: 0.2.3
9
+ - 4
10
+ version: 0.2.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Thomas Kadauke
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-10-14 00:00:00 +02:00
18
+ date: 2011-10-31 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies: []
21
21