resque-workers-lock 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +7 -4
- data/test/lock_test.rb +2 -1
- metadata +5 -7
data/README.md
CHANGED
@@ -6,7 +6,7 @@ gem 'resque-workers-lock'
|
|
6
6
|
```
|
7
7
|
|
8
8
|
## What does it do?
|
9
|
-
If resque jobs have the same lock applied this means that those jobs cannot be processed simultaneously by two or more workers.
|
9
|
+
If resque jobs have the same lock applied this means that those jobs cannot be processed simultaneously by two or more workers. When this situation occurs the second job gets pushed back to the queue.
|
10
10
|
|
11
11
|
## What is the default lock?
|
12
12
|
By default the lock is the instance name + arguments (just like the classic resque-lock). Override this lock to lock on specific arguments.
|
@@ -19,18 +19,21 @@ This example shows how you can use the workers-lock to prevent two jobs with the
|
|
19
19
|
``` ruby
|
20
20
|
require 'resque/plugins/workers/lock'
|
21
21
|
|
22
|
-
class
|
22
|
+
class Parser
|
23
23
|
extend Resque::Plugins::Workers::Lock
|
24
24
|
|
25
|
-
|
25
|
+
# Lock method has the same arguments as the self.perform
|
26
|
+
def self.lock(domain, arg2, arg3)
|
26
27
|
return domain
|
27
28
|
end
|
28
29
|
|
29
|
-
|
30
|
+
# Perform method with some arguments
|
31
|
+
def self.perform(domain, arg2, arg3)
|
30
32
|
# do the work
|
31
33
|
end
|
32
34
|
end
|
33
35
|
```
|
36
|
+
In this example `domain` is used to specify certain types of jobs that are not allowed to run at the same time. For example: if you create three jobs with the domain argument google.com, google.com and yahoo.com, the two google.com jobs will never run at the same time.
|
34
37
|
|
35
38
|
## Requeue loop
|
36
39
|
When a job is requeue'ed there is a small delay (1 second by default) before the worker places the job actually back in the queue. Let's say you have two jobs left, and one job is taking 15 seconds on the first worker and the other similar job is being blocked by the second worker. The second worker will continuously try to put the job back in the queue and it will try to process it again (racing for 15 seconds untill the other job has finished). This only happens when there are no other (not locked) jobs in the queue.
|
data/test/lock_test.rb
CHANGED
@@ -39,6 +39,7 @@ class LockTest < Test::Unit::TestCase
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def test_lock
|
42
|
-
# TODO: test that two workers are not processing two jobs
|
42
|
+
# TODO: test that two workers are not processing two jobs with same locks
|
43
|
+
# This is pretty hard to do, contributors are welcome!
|
43
44
|
end
|
44
45
|
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.0.
|
4
|
+
version: 1.0.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-07-
|
12
|
+
date: 2012-07-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: resque
|
@@ -59,11 +59,9 @@ dependencies:
|
|
59
59
|
- - ! '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
|
-
description: ! "A Resque plugin.
|
63
|
-
simultaneously
|
64
|
-
|
65
|
-
\ def self.lock(domain)\n return domain\n end\n\n def
|
66
|
-
self.perform(domain)\n # do the work\n end\n end\n"
|
62
|
+
description: ! "A Resque plugin. Two or more jobs with the same lock cannot be processed
|
63
|
+
simultaneously by multiple workers. \nWhen this situation occurs the second job
|
64
|
+
gets pushed back to the queue.\n"
|
67
65
|
email: bartolsthoorn@gmail.com
|
68
66
|
executables: []
|
69
67
|
extensions: []
|