say_when 0.2.5 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -21,23 +21,23 @@ module SayWhen
21
21
  before_create :set_defaults
22
22
 
23
23
  def self.acquire_next(no_later_than)
24
- SayWhen::Storage::ActiveRecord::Job.transaction do
25
- # select and lock the next job that needs executin' (status waiting, and after no_later_than)
26
- next_job = find(:first,
27
- :lock => true,
28
- :order => 'next_fire_at ASC',
29
- :conditions => ['status = ? and ? >= next_fire_at',
30
- STATE_WAITING,
31
- no_later_than.in_time_zone('UTC')])
32
-
33
- # make sure there is a job ready to run
34
- return nil if next_job.nil?
35
-
36
- # set status to acquired to take it out of rotation
37
- next_job.update_attribute(:status, STATE_ACQUIRED)
38
-
39
- return next_job
24
+ @next_job = nil
25
+ hide_logging do
26
+ SayWhen::Storage::ActiveRecord::Job.transaction do
27
+ # select and lock the next job that needs executin' (status waiting, and after no_later_than)
28
+ @next_job = find(:first,
29
+ :lock => true,
30
+ :order => 'next_fire_at ASC',
31
+ :conditions => ['status = ? and ? >= next_fire_at',
32
+ STATE_WAITING,
33
+ no_later_than.in_time_zone('UTC')])
34
+
35
+ # set status to acquired to take it out of rotation
36
+ @next_job.update_attribute(:status, STATE_ACQUIRED) unless @next_job.nil?
37
+
38
+ end
40
39
  end
40
+ @next_job
41
41
  end
42
42
 
43
43
  def set_defaults
@@ -79,6 +79,21 @@ module SayWhen
79
79
  execution.save!
80
80
  result
81
81
  end
82
+
83
+ protected
84
+
85
+ def self.hide_logging
86
+ old_logger = nil
87
+ begin
88
+ old_logger = ::ActiveRecord::Base.logger
89
+ ::ActiveRecord::Base.logger = nil
90
+
91
+ yield
92
+
93
+ ensure
94
+ ::ActiveRecord::Base.logger = old_logger
95
+ end
96
+ end
82
97
 
83
98
  end
84
99
 
@@ -1,3 +1,3 @@
1
1
  module SayWhen
2
- VERSION = "0.2.5"
2
+ VERSION = "0.2.6"
3
3
  end
data/lib/say_when.rb CHANGED
@@ -18,8 +18,11 @@ module SayWhen
18
18
  end
19
19
 
20
20
  def SayWhen.logger
21
- unless defined?(@@logger)
22
- @@logger = Rails.logger if defined?(Rails.logger) && Rails.logger
21
+ if !defined?(@@logger) || !@@logger
22
+ if defined?(Rails.logger) && Rails.logger
23
+ @@logger = Rails.logger
24
+ end
25
+
23
26
  @@logger = Logger.new(STDOUT) unless defined?(@@logger)
24
27
  end
25
28
  @@logger
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: say_when
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 5
10
- version: 0.2.5
9
+ - 6
10
+ version: 0.2.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Andrew Kuklewicz
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-10-11 00:00:00 Z
18
+ date: 2012-10-30 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: activemessaging