Skip to content
Browse files

Enqueue lock functionality removed and rake test improved

  • Loading branch information...
1 parent 43c4df7 commit fd98beb2187f314770173c16de3fd2ff59173cd2 @bartolsthoorn committed Dec 19, 2012
Showing with 58 additions and 26 deletions.
  1. +23 −0 README.md
  2. +4 −0 Rakefile
  3. +2 −2 resque-workers-lock.gemspec
  4. +3 −24 test/lock_test.rb
  5. +26 −0 test/unique_job.rb
View
23 README.md
@@ -60,3 +60,26 @@ Please note that setting this value to 5 seconds will keep the worker idle for 5
## Possibilities to prevent the loop
Do a delayed resque (re)queue. However, this will have approximately the same results and will require a large extra chunk of code and rake configurations.
+
+## Run workers for the test
+To run the tests using `rake test` properly, make sure there are a few workers running:
+```
+$ redis-server
+$ VVERBOSE=1 COUNT=4 QUEUE=* rake resque:work
+```
+
+```
+➜ resque-workers-lock git:(master) ✗ rake test
+Run options:
+
+# Running tests:
+
+...
+
+Finished tests in 10.426519s, 0.2877 tests/s, 0.3836 assertions/s.
+
+3 tests, 4 assertions, 0 failures, 0 errors, 0 skips
+```
+
+## Authors/Contributors
+[nicholaides](https://github.com/nicholaides)
View
4 Rakefile
@@ -8,4 +8,8 @@ Rake::TestTask.new do |t|
t.libs << 'lib'
t.pattern = 'test/**/*_test.rb'
t.verbose = false
+end
+
+task "resque:setup" do
+ require_relative "test/unique_job"
end
View
4 resque-workers-lock.gemspec
@@ -1,11 +1,11 @@
Gem::Specification.new do |s|
s.name = "resque-workers-lock"
- s.version = "1.6"
+ s.version = "1.7"
s.date = Time.now.strftime('%Y-%m-%d')
s.summary = "Resque plugin, prevent specific jobs to be processed simultaneously by multiple workers."
s.homepage = "http://github.com/bartolsthoorn/resque-workers-lock"
s.email = "bartolsthoorn@gmail.com"
- s.authors = ["Bart Olsthoorn"]
+ s.authors = ["Bart Olsthoorn", "Mike Nicholaides"]
s.has_rdoc = false
s.files = %w( README.md Rakefile LICENSE )
View
27 test/lock_test.rb
@@ -3,31 +3,10 @@
require 'tempfile'
require 'timeout'
-class LockTest < Test::Unit::TestCase
- class UniqueJob
- extend Resque::Plugins::Workers::Lock
- def queue; :lock_test end
-
- def self.worker_lock_timeout(*)
- 5
- end
+require_relative 'unique_job'
- def self.lock_workers(*)
- self.name
- end
-
- def self.append_output filename, string
- File.open(filename, 'a') do |output_file|
- output_file.puts string
- end
- end
-
- def self.perform params
- append_output params['output_file'], "starting #{params['job']}"
- sleep(params['sleep'] || 1)
- append_output params['output_file'], "finished #{params['job']}"
- end
- end
+class LockTest < Test::Unit::TestCase
+
def setup
Resque.redis.del(UniqueJob.get_lock_workers)
View
26 test/unique_job.rb
@@ -0,0 +1,26 @@
+require File.expand_path('../../lib/resque/plugins/workers/lock', __FILE__)
+
+class UniqueJob
+ extend Resque::Plugins::Workers::Lock
+ @queue = :lock_test
+
+ def self.worker_lock_timeout(*)
+ 5
+ end
+
+ def self.lock_workers(*)
+ self.name
+ end
+
+ def self.append_output filename, string
+ File.open(filename, 'a') do |output_file|
+ output_file.puts string
+ end
+ end
+
+ def self.perform params
+ append_output params['output_file'], "starting #{params['job']}"
+ sleep(params['sleep'] || 1)
+ append_output params['output_file'], "finished #{params['job']}"
+ end
+end

0 comments on commit fd98beb

Please sign in to comment.
Something went wrong with that request. Please try again.