ealdent-resque-lock 0.1.2 → 1.0.0

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/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
@@ -3,7 +3,7 @@ Resque Lock
3
3
 
4
4
  A [Resque][rq] plugin. Requires Resque 1.7.0.
5
5
 
6
- If you want only one instance of your job running at a time, extend it
6
+ If you want only one instance of your job queued at a time, extend it
7
7
  with this module.
8
8
 
9
9
 
@@ -19,10 +19,8 @@ For example:
19
19
  end
20
20
  end
21
21
 
22
- While other UpdateNetworkGraph jobs will be placed on the queue,
23
- the Locked class will check Redis to see if any others are
24
- executing with the same arguments before beginning. If another
25
- 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.
26
24
 
27
25
  If you want to define the key yourself you can override the
28
26
  `lock` class method in your subclass, e.g.
@@ -41,7 +39,7 @@ If you want to define the key yourself you can override the
41
39
  end
42
40
 
43
41
  The above modification will ensure only one job of class
44
- UpdateNetworkGraph is running at a time, regardless of the
42
+ UpdateNetworkGraph is queued at a time, regardless of the
45
43
  repo_id. Normally a job is locked using a combination of its
46
44
  class name and arguments.
47
45
 
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.exists(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), Time.now.utc)
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,17 +4,21 @@ 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)
14
20
  end
15
- end
16
21
 
17
- class LockTest < Test::Unit::TestCase
18
22
  def test_lint
19
23
  assert_nothing_raised do
20
24
  Resque::Plugin.lint(Resque::Plugins::Lock)
@@ -24,19 +28,13 @@ class LockTest < Test::Unit::TestCase
24
28
  def test_version
25
29
  major, minor, patch = Resque::Version.split('.')
26
30
  assert_equal 1, major.to_i
27
- assert minor.to_i >= 7
31
+ assert minor.to_i >= 17
32
+ assert Resque::Plugin.respond_to?(:before_enqueue_hooks)
28
33
  end
29
34
 
30
35
  def test_lock
31
36
  3.times { Resque.enqueue(Job) }
32
- worker = Resque::Worker.new(:test)
33
-
34
- workers = []
35
- 3.times do
36
- workers << Thread.new { worker.process }
37
- end
38
- workers.each { |t| t.join }
39
37
 
40
- assert_equal 1, $counter
38
+ assert_equal 1, Resque.redis.llen('queue:lock_test')
41
39
  end
42
40
  end
metadata CHANGED
@@ -1,28 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ealdent-resque-lock
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
5
- prerelease: false
4
+ hash: 23
5
+ prerelease:
6
6
  segments:
7
- - 0
8
7
  - 1
9
- - 2
10
- version: 0.1.2
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Chris Wanstrath
14
+ - Ray Krueger
14
15
  - Jason Adams
15
16
  autorequire:
16
17
  bindir: bin
17
18
  cert_chain: []
18
19
 
19
- date: 2010-10-14 00:00:00 -04:00
20
+ date: 2011-11-17 00:00:00 -05:00
20
21
  default_executable:
21
22
  dependencies: []
22
23
 
23
24
  description: |
24
25
  A Resque plugin. If you want only one instance of your job
25
- running at a time, extend it with this module. This version
26
+ queued at a time, extend it with this module. This version
26
27
  stores the timestamp in the lock.
27
28
 
28
29
  For example:
@@ -78,9 +79,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
78
79
  requirements: []
79
80
 
80
81
  rubyforge_project:
81
- rubygems_version: 1.3.7
82
+ rubygems_version: 1.5.2
82
83
  signing_key:
83
84
  specification_version: 3
84
- summary: A Resque plugin for ensuring only one instance of your job is running at a time.
85
+ summary: A fork by Jason Adams of a Resque plugin for ensuring only one instance of your job is running at a time.
85
86
  test_files: []
86
87