resque-workers-lock 1.4 → 1.5
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/Rakefile +4 -0
- data/test/lock_test.rb +1 -21
- data/test/lock_worker.rb +22 -0
- metadata +2 -1
data/Rakefile
CHANGED
data/test/lock_test.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'test/unit'
|
2
2
|
require 'resque/plugins/workers/lock'
|
3
|
+
require_relative 'lock_worker'
|
3
4
|
|
4
5
|
class LockTest < Test::Unit::TestCase
|
5
6
|
class SimilarJob
|
@@ -71,30 +72,9 @@ class LockTest < Test::Unit::TestCase
|
|
71
72
|
assert_equal 0, Resque.redis.llen('queue:lock_test')
|
72
73
|
end
|
73
74
|
|
74
|
-
# Sleep job, for testing that two workers are not processing two jobs with
|
75
|
-
# the same lock.
|
76
|
-
class SimilarSleepJob
|
77
|
-
extend Resque::Plugins::Workers::Lock
|
78
|
-
@queue = :lock_test_workers
|
79
|
-
|
80
|
-
def self.lock_enqueue(id)
|
81
|
-
false
|
82
|
-
end
|
83
|
-
|
84
|
-
def self.lock_workers(id)
|
85
|
-
return id.to_s
|
86
|
-
end
|
87
|
-
|
88
|
-
def self.perform(id)
|
89
|
-
File.open('test/test.txt', 'a') {|f| f.write('1') }
|
90
|
-
sleep(5)
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
75
|
# To test this, make sure to run `TERM_CHILD=1 COUNT=2 VVERBOSE=1 QUEUES=* rake resque:work`
|
95
76
|
def test_lock
|
96
77
|
2.times { Resque.enqueue(SimilarSleepJob, 'writing_and_sleeping') }
|
97
|
-
SimilarSleepJob.perform('abc')
|
98
78
|
|
99
79
|
# After 3 seconds only 1 job had the change of running
|
100
80
|
sleep(3)
|
data/test/lock_worker.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'resque'
|
2
|
+
require 'resque/plugins/workers/lock'
|
3
|
+
|
4
|
+
# Sleep job, for testing that two workers are not processing two jobs with
|
5
|
+
# the same lock.
|
6
|
+
class SimilarSleepJob
|
7
|
+
extend Resque::Plugins::Workers::Lock
|
8
|
+
@queue = :lock_test_workers
|
9
|
+
|
10
|
+
def self.lock_enqueue(id)
|
11
|
+
false
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.lock_workers(id)
|
15
|
+
return id.to_s
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.perform(id)
|
19
|
+
File.open('test/test.txt', 'a') {|f| f.write('1') }
|
20
|
+
sleep(5)
|
21
|
+
end
|
22
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: resque-workers-lock
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '1.
|
4
|
+
version: '1.5'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -72,6 +72,7 @@ files:
|
|
72
72
|
- LICENSE
|
73
73
|
- lib/resque/plugins/workers/lock.rb
|
74
74
|
- test/lock_test.rb
|
75
|
+
- test/lock_worker.rb
|
75
76
|
homepage: http://github.com/bartolsthoorn/resque-workers-lock
|
76
77
|
licenses: []
|
77
78
|
post_install_message:
|