resque-lock 0.1.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2010 Chris Wanstrath
1
+ Copyright (c) Chris Wanstrath, Ray Krueger
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -1,8 +1,11 @@
1
1
  Resque Lock
2
2
  ===========
3
3
 
4
- A [Resque][rq] plugin. If you want only one instance of your job
5
- running at a time, extend it with this module.
4
+ A [Resque][rq] plugin. Requires Resque 1.7.0.
5
+
6
+ If you want only one instance of your job queued at a time, extend it
7
+ with this module.
8
+
6
9
 
7
10
  For example:
8
11
 
@@ -16,10 +19,8 @@ For example:
16
19
  end
17
20
  end
18
21
 
19
- While other UpdateNetworkGraph jobs will be placed on the queue,
20
- the Locked class will check Redis to see if any others are
21
- executing with the same arguments before beginning. If another
22
- is executing the job will be aborted.
22
+ While this job is queued or running, no other UpdateNetworkGraph
23
+ jobs with the same arguments will be placed on the queue.
23
24
 
24
25
  If you want to define the key yourself you can override the
25
26
  `lock` class method in your subclass, e.g.
@@ -38,14 +39,8 @@ If you want to define the key yourself you can override the
38
39
  end
39
40
 
40
41
  The above modification will ensure only one job of class
41
- UpdateNetworkGraph is running at a time, regardless of the
42
+ UpdateNetworkGraph is queued at a time, regardless of the
42
43
  repo_id. Normally a job is locked using a combination of its
43
44
  class name and arguments.
44
45
 
45
-
46
- Dependencies
47
- ------------
48
-
49
- * Resque 1.7.0
50
-
51
46
  [rq]: http://github.com/defunkt/resque
data/Rakefile CHANGED
@@ -24,26 +24,3 @@ else
24
24
  t.verbose = false
25
25
  end
26
26
  end
27
-
28
- #
29
- # Gems
30
- #
31
-
32
- begin
33
- require 'mg'
34
- MG.new("resque-lock.gemspec")
35
-
36
- desc "Build a gem."
37
- task :gem => :package
38
-
39
- # Ensure tests pass before pushing a gem.
40
- task :gemcutter => :test
41
-
42
- desc "Push a new version to Gemcutter and publish docs."
43
- task :publish => :gemcutter do
44
- sh "git push origin master --tags"
45
- end
46
- rescue LoadError
47
- warn "mg not available."
48
- warn "Install it with: gem i mg"
49
- end
@@ -1,6 +1,6 @@
1
1
  module Resque
2
2
  module Plugins
3
- # If you want only one instance of your job running at a time,
3
+ # If you want only one instance of your job queued at a time,
4
4
  # extend it with this module.
5
5
  #
6
6
  # For example:
@@ -15,10 +15,10 @@ module Resque
15
15
  # end
16
16
  # end
17
17
  #
18
- # While other UpdateNetworkGraph jobs will be placed on the queue,
19
- # the Lock class will check Redis to see if any others are
20
- # executing with the same arguments before beginning. If another
21
- # is executing the job will be aborted.
18
+ # No other UpdateNetworkGraph jobs will be placed on the queue,
19
+ # the QueueLock class will check Redis to see if any others are
20
+ # queued with the same arguments before queueing. If another
21
+ # is queued the enqueue will be aborted.
22
22
  #
23
23
  # If you want to define the key yourself you can override the
24
24
  # `lock` class method in your subclass, e.g.
@@ -48,16 +48,11 @@ module Resque
48
48
  "lock:#{name}-#{args.to_s}"
49
49
  end
50
50
 
51
- # Convenience method, not used internally.
52
- def locked?(*args)
53
- Resque.redis.exist(lock(*args))
51
+ def before_enqueue_lock(*args)
52
+ Resque.redis.setnx(lock(*args), true)
54
53
  end
55
54
 
56
- # Where the magic happens.
57
55
  def around_perform_lock(*args)
58
- # Abort if another job has created a lock.
59
- return unless Resque.redis.setnx(lock(*args), true)
60
-
61
56
  begin
62
57
  yield
63
58
  ensure
@@ -69,3 +64,4 @@ module Resque
69
64
  end
70
65
  end
71
66
  end
67
+
@@ -4,31 +4,37 @@ require 'resque/plugins/lock'
4
4
 
5
5
  $counter = 0
6
6
 
7
- class Job
8
- extend Resque::Plugins::Lock
9
- @queue = :test
7
+ class LockTest < Test::Unit::TestCase
8
+ class Job
9
+ extend Resque::Plugins::Lock
10
+ @queue = :lock_test
10
11
 
11
- def self.perform
12
- $counter += 1
13
- sleep 1
12
+ def self.perform
13
+ raise "Woah woah woah, that wasn't supposed to happen"
14
+ end
15
+ end
16
+
17
+ def setup
18
+ Resque.redis.del('queue:lock_test')
19
+ Resque.redis.del(Job.lock)
20
+ end
21
+
22
+ def test_lint
23
+ assert_nothing_raised do
24
+ Resque::Plugin.lint(Resque::Plugins::Lock)
25
+ end
14
26
  end
15
- end
16
27
 
17
- class LockTest < Test::Unit::TestCase
18
28
  def test_version
19
- assert_equal '1.7.0', Resque::Version
29
+ major, minor, patch = Resque::Version.split('.')
30
+ assert_equal 1, major.to_i
31
+ assert minor.to_i >= 17
32
+ assert Resque::Plugin.respond_to?(:before_enqueue_hooks)
20
33
  end
21
34
 
22
35
  def test_lock
23
36
  3.times { Resque.enqueue(Job) }
24
- worker = Resque::Worker.new(:test)
25
-
26
- workers = []
27
- 3.times do
28
- workers << Thread.new { worker.process }
29
- end
30
- workers.each { |t| t.join }
31
37
 
32
- assert_equal 1, $counter
38
+ assert_equal 1, Resque.redis.llen('queue:lock_test')
33
39
  end
34
40
  end
metadata CHANGED
@@ -1,21 +1,28 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: resque-lock
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ hash: 23
5
+ prerelease:
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
5
11
  platform: ruby
6
12
  authors:
7
13
  - Chris Wanstrath
14
+ - Ray Krueger
8
15
  autorequire:
9
16
  bindir: bin
10
17
  cert_chain: []
11
18
 
12
- date: 2010-04-01 00:00:00 -07:00
19
+ date: 2011-08-18 00:00:00 -07:00
13
20
  default_executable:
14
21
  dependencies: []
15
22
 
16
23
  description: |
17
24
  A Resque plugin. If you want only one instance of your job
18
- running at a time, extend it with this module.
25
+ queued at a time, extend it with this module.
19
26
 
20
27
  For example:
21
28
 
@@ -50,23 +57,29 @@ rdoc_options: []
50
57
  require_paths:
51
58
  - lib
52
59
  required_ruby_version: !ruby/object:Gem::Requirement
60
+ none: false
53
61
  requirements:
54
62
  - - ">="
55
63
  - !ruby/object:Gem::Version
64
+ hash: 3
65
+ segments:
66
+ - 0
56
67
  version: "0"
57
- version:
58
68
  required_rubygems_version: !ruby/object:Gem::Requirement
69
+ none: false
59
70
  requirements:
60
71
  - - ">="
61
72
  - !ruby/object:Gem::Version
73
+ hash: 3
74
+ segments:
75
+ - 0
62
76
  version: "0"
63
- version:
64
77
  requirements: []
65
78
 
66
79
  rubyforge_project:
67
- rubygems_version: 1.3.5
80
+ rubygems_version: 1.5.2
68
81
  signing_key:
69
82
  specification_version: 3
70
- summary: A Resque plugin for ensuring only one instance of your job is running at a time.
83
+ summary: A Resque plugin for ensuring only one instance of your job is queued at a time.
71
84
  test_files: []
72
85