resque-lock-timeout 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/HISTORY.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.4.1 (2012-11-19)
2
+
3
+ * Bug fix, allow `@loner` job to be enqueued if timeout expires.
4
+
1
5
  ## 0.4.0 (2012-11-09)
2
6
 
3
7
  * Add `@loner` boolean option to prevent job being enqueued if already
@@ -110,11 +110,13 @@ module Resque
110
110
  @loner ||= false
111
111
  end
112
112
 
113
- # Convenience method, not used internally.
113
+ # Convenience method to check if job is locked and lock did not expire.
114
114
  #
115
115
  # @return [Boolean] true if the job is locked by someone
116
116
  def locked?(*args)
117
- lock_redis.exists(redis_lock_key(*args))
117
+ lock_until = lock_redis.get(redis_lock_key(*args))
118
+ return (lock_until.to_i > Time.now.to_i) if lock_timeout(*args) > 0
119
+ !lock_until.nil?
118
120
  end
119
121
 
120
122
  # @abstract
@@ -145,7 +147,7 @@ module Resque
145
147
  # @param [Array] args job arguments
146
148
  def before_enqueue_lock(*args)
147
149
  if loner
148
- if locked?(*args)
150
+ if locked?(*args)
149
151
  # Same job is currently running
150
152
  loner_enqueue_failed(*args)
151
153
  false
@@ -192,4 +192,14 @@ class LockTest < MiniTest::Unit::TestCase
192
192
  assert_equal 1, $success, 'One job should increment success'
193
193
  end
194
194
 
195
+ def test_loner_job_should_get_enqueued_if_timeout_expired
196
+ Resque.enqueue(LonelyTimeoutExpiringJob)
197
+ thread = Thread.new { @worker.process }
198
+
199
+ sleep 2.1 # Wait for job to finish.
200
+
201
+ Resque.enqueue(LonelyTimeoutExpiringJob)
202
+ assert_equal 1, Resque.size(:test), "Should be able to enqueue a loner job if one previously finished after the timeout"
203
+ end
204
+
195
205
  end
@@ -146,3 +146,15 @@ class LonelyTimeoutJob
146
146
  $enqueue_failed += 1
147
147
  end
148
148
  end
149
+
150
+ # This job won't complete before it's timeout
151
+ class LonelyTimeoutExpiringJob
152
+ extend Resque::Plugins::LockTimeout
153
+ @queue = :test
154
+ @loner = true
155
+ @lock_timeout = 1
156
+
157
+ def self.perform
158
+ sleep 2
159
+ end
160
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: resque-lock-timeout
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2012-11-09 00:00:00.000000000 Z
14
+ date: 2012-11-19 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: resque