resque_solo 0.0.4 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b7d4f959f0665b35ce76f33a23eef5e18aade292
4
- data.tar.gz: c67470bf93eb65838599478b4aeafcef7801f81a
3
+ metadata.gz: dc87df1fa353f94c1d75b20c2dc6ef9f5978637b
4
+ data.tar.gz: 51df2fed96c31280f6ed8fb64851529fc75fcda4
5
5
  SHA512:
6
- metadata.gz: 48bfa1dde895f27c45112dbb3e39b3fd54e9b91fafa9cc142b471b18c68be74d59ce67fe2357c8104eea5d7611e94eed061fa1b374874c561980cd5cc82caa88
7
- data.tar.gz: c1459dca21cb192f986fdb8f447226d66794f4d26f3b666cf27fe525cbc59ae36eb83e47d55d012f14a6a2b5146ebcc1f7487ad79c170263781fc33547475df3
6
+ metadata.gz: 927e45014a436a39aba1017cbd153d43218f3d82bee878f88f1efbc0e0d0d86e854eb03b46a626df9ad377c77b73e2e76286e7c73fb314cd9466fa8ef4e1ccf6
7
+ data.tar.gz: ab499a6bb2587de31fd05a37d4092a59a79572d67e1349ff86d836066b85249be8d7505883935e187b81e25f5f2d3fa19055f4658f3e05b5a680bc45e90fde3c
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- ruby-2.0.0
1
+ ruby-2.1.1
data/.travis.yml CHANGED
@@ -1,4 +1,5 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.9.3
3
+ - 2.1
4
4
  - 2.0.0
5
+ - 1.9.3
data/Gemfile CHANGED
@@ -1,12 +1,9 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  group :test do
4
- gem 'test-unit'
5
- gem 'mocha'
6
- gem 'shoulda-context'
7
- gem 'pry'
8
- gem 'pry-byebug', platform: :mri_20
9
- gem 'fakeredis'
4
+ unless ENV['TRAVIS']
5
+ gem 'pry-byebug', platform: :mri_21
6
+ end
10
7
  gem 'simplecov', require: false
11
8
  end
12
9
 
data/README.md CHANGED
@@ -1,9 +1,9 @@
1
1
  # ResqueSolo
2
2
 
3
- [![Gem Version](https://badge.fury.io/rb/resque_solo.png)][gem]
4
- [![Build Status](https://api.travis-ci.org/neighborland/resque_solo.png)][build]
3
+ [![Gem Version](http://img.shields.io/gem/v/resque_solo.svg)][gem]
4
+ [![Build Status](http://img.shields.io/travis/neighborland/resque_solo.svg)][build]
5
5
 
6
- [gem]: http://badge.fury.io/rb/resque_solo
6
+ [gem]: http://rubygems.org/gems/resque_solo
7
7
  [build]: https://travis-ci.org/neighborland/resque_solo
8
8
 
9
9
  ResqueSolo is a resque plugin to add unique jobs to resque.
@@ -18,7 +18,9 @@ It removes the dependency on `Resque::Helpers`, which is deprecated for resque 2
18
18
 
19
19
  Add the gem to your Gemfile:
20
20
 
21
- gem 'resque_solo'
21
+ ```ruby
22
+ gem 'resque_solo'
23
+ ```
22
24
 
23
25
  ## Usage
24
26
 
@@ -49,3 +51,16 @@ Resque.enqueued? UpdateCat, 1
49
51
  Resque.enqueued_in? :dogs, UpdateCat, 1
50
52
  => false
51
53
  ```
54
+
55
+ ### Options
56
+
57
+ #### `lock_after_execution_period`
58
+
59
+ By default, lock_after_execution_period is 0 and `enqueued?` becomes false as soon as the job
60
+ is being worked on.
61
+
62
+ The `lock_after_execution_period` setting can be used to delay when the unique job key is deleted
63
+ (i.e. when `enqueued?` becomes `false`). For example, if you have a long-running unique job that
64
+ takes around 10 seconds, and you don't want to requeue another job until you are sure it is done,
65
+ you could set `lock_after_execution_period = 20`. Or if you never want to run a long running
66
+ job more than once per minute, set `lock_after_execution_period = 60`.
@@ -1,3 +1,3 @@
1
1
  module ResqueSolo
2
- VERSION = "0.0.4"
2
+ VERSION = "0.1.0"
3
3
  end
data/resque_solo.gemspec CHANGED
@@ -22,6 +22,8 @@ Gem::Specification.new do |spec|
22
22
 
23
23
  spec.add_dependency "resque", "~> 1.25.1"
24
24
 
25
- spec.add_development_dependency "bundler", "~> 1.3"
26
- spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "bundler", "~> 1.5"
26
+ spec.add_development_dependency "fakeredis", "~> 0.4"
27
+ spec.add_development_dependency "minitest", "~> 5.3"
28
+ spec.add_development_dependency "rake", "~> 10.1"
27
29
  end
data/test/job_test.rb CHANGED
@@ -1,17 +1,17 @@
1
1
  require 'test_helper'
2
2
 
3
- class JobTest < Test::Unit::TestCase
4
- setup do
3
+ class JobTest < MiniTest::Spec
4
+ before do
5
5
  Resque.redis.flushall
6
6
  end
7
7
 
8
- should "enqueue identical jobs once" do
8
+ it "enqueue identical jobs once" do
9
9
  Resque.enqueue FakeUniqueJob, "x"
10
10
  Resque.enqueue FakeUniqueJob, "x"
11
11
  assert_equal 1, Resque.size(:unique)
12
12
  end
13
13
 
14
- should "allow the same jobs to be executed one after the other" do
14
+ it "allow the same jobs to be executed one after the other" do
15
15
  Resque.enqueue FakeUniqueJob, "foo"
16
16
  Resque.enqueue FakeUniqueJob, "foo"
17
17
  assert_equal 1, Resque.size(:unique)
@@ -22,19 +22,19 @@ class JobTest < Test::Unit::TestCase
22
22
  assert_equal 1, Resque.size(:unique)
23
23
  end
24
24
 
25
- should "consider equivalent hashes regardless of key order" do
25
+ it "consider equivalent hashes regardless of key order" do
26
26
  Resque.enqueue FakeUniqueJob, bar: 1, foo: 2
27
27
  Resque.enqueue FakeUniqueJob, foo: 2, bar: 1
28
28
  assert_equal 1, Resque.size(:unique)
29
29
  end
30
30
 
31
- should "treat string and symbol keys equally" do
31
+ it "treat string and symbol keys equally" do
32
32
  Resque.enqueue FakeUniqueJob, bar: 1, foo: 1
33
33
  Resque.enqueue FakeUniqueJob, bar: 1, "foo" => 1
34
34
  assert_equal 1, Resque.size(:unique)
35
35
  end
36
36
 
37
- should "mark jobs as unqueued, when Job.destroy is killing them" do
37
+ it "mark jobs as unqueued, when Job.destroy is killing them" do
38
38
  Resque.enqueue FakeUniqueJob, "foo"
39
39
  Resque.enqueue FakeUniqueJob, "foo"
40
40
  assert_equal 1, Resque.size(:unique)
@@ -45,7 +45,7 @@ class JobTest < Test::Unit::TestCase
45
45
  assert_equal 1, Resque.size(:unique)
46
46
  end
47
47
 
48
- should "mark jobs as unqueued when they raise an exception" do
48
+ it "mark jobs as unqueued when they raise an exception" do
49
49
  2.times { Resque.enqueue( FailingUniqueJob, "foo" ) }
50
50
  assert_equal 1, Resque.size(:unique)
51
51
  worker = Resque::Worker.new(:unique)
@@ -55,13 +55,13 @@ class JobTest < Test::Unit::TestCase
55
55
  assert_equal 1, Resque.size(:unique)
56
56
  end
57
57
 
58
- should "report if a unique job is enqueued" do
58
+ it "report if a unique job is enqueued" do
59
59
  Resque.enqueue FakeUniqueJob, "foo"
60
60
  assert Resque.enqueued?(FakeUniqueJob, "foo")
61
61
  refute Resque.enqueued?(FakeUniqueJob, "bar")
62
62
  end
63
63
 
64
- should "report if a job is enqueued" do
64
+ it "report if a unique job is enqueued in another queue" do
65
65
  default_queue = FakeUniqueJob.instance_variable_get(:@queue)
66
66
  FakeUniqueJob.instance_variable_set(:@queue, :other)
67
67
  Resque.enqueue FakeUniqueJob, "foo"
@@ -70,7 +70,7 @@ class JobTest < Test::Unit::TestCase
70
70
  refute Resque.enqueued?(FakeUniqueJob, "foo")
71
71
  end
72
72
 
73
- should "cleanup when a queue is destroyed" do
73
+ it "cleanup when a queue is destroyed" do
74
74
  Resque.enqueue FakeUniqueJob, "foo"
75
75
  Resque.enqueue FailingUniqueJob, "foo"
76
76
  Resque.remove_queue(:unique)
@@ -78,7 +78,7 @@ class JobTest < Test::Unit::TestCase
78
78
  assert_equal 1, Resque.size(:unique)
79
79
  end
80
80
 
81
- should "honor ttl in the redis key" do
81
+ it "honor ttl in the redis key" do
82
82
  Resque.enqueue UniqueJobWithTtl
83
83
  assert Resque.enqueued?(UniqueJobWithTtl)
84
84
  keys = Resque.redis.keys "solo:queue:unique_with_ttl:job:*"
@@ -86,7 +86,7 @@ class JobTest < Test::Unit::TestCase
86
86
  assert_in_delta UniqueJobWithTtl.ttl, Resque.redis.ttl(keys.first), 2
87
87
  end
88
88
 
89
- should "not allow the same job to be enqueued after execution if lock_after_execution_period is set" do
89
+ it "not allow the same job to be enqueued after execution if lock_after_execution_period is set" do
90
90
  Resque.enqueue UniqueJobWithLock, "foo"
91
91
  Resque.enqueue UniqueJobWithLock, "foo"
92
92
  assert_equal 1, Resque.size(:unique_with_lock)
@@ -96,7 +96,7 @@ class JobTest < Test::Unit::TestCase
96
96
  assert_equal 0, Resque.size(:unique_with_lock)
97
97
  end
98
98
 
99
- should "honor lock_after_execution_period in the redis key" do
99
+ it "honor lock_after_execution_period in the redis key" do
100
100
  Resque.enqueue UniqueJobWithLock
101
101
  Resque.reserve(:unique_with_lock)
102
102
  keys = Resque.redis.keys "solo:queue:unique_with_lock:job:*"
@@ -104,4 +104,4 @@ class JobTest < Test::Unit::TestCase
104
104
  assert_in_delta UniqueJobWithLock.lock_after_execution_period, Resque.redis.ttl(keys.first), 2
105
105
  end
106
106
 
107
- end
107
+ end
data/test/queue_test.rb CHANGED
@@ -1,54 +1,54 @@
1
1
  require 'test_helper'
2
2
 
3
3
  module ResqueSolo
4
- class QueueTest < Test::Unit::TestCase
5
- context ".is_unique?" do
6
- should "be false for non-unique job" do
4
+ class QueueTest < MiniTest::Spec
5
+ describe ".is_unique?" do
6
+ it "is false for non-unique job" do
7
7
  refute Queue.is_unique?(class: 'FakeJob')
8
8
  end
9
9
 
10
- should "be false for invalid job class" do
10
+ it "is false for invalid job class" do
11
11
  refute Queue.is_unique?(class: 'InvalidJob')
12
12
  end
13
13
 
14
- should "be true for unique job" do
14
+ it "is true for unique job" do
15
15
  assert Queue.is_unique?(class: 'FakeUniqueJob')
16
16
  end
17
17
  end
18
18
 
19
- context ".item_ttl" do
20
- should "be -1 for non-unique job" do
19
+ describe ".item_ttl" do
20
+ it "is -1 for non-unique job" do
21
21
  assert_equal -1, Queue.item_ttl(class: 'FakeJob')
22
22
  end
23
23
 
24
- should "be -1 for invalid job class" do
24
+ it "is -1 for invalid job class" do
25
25
  assert_equal -1, Queue.item_ttl(class: 'InvalidJob')
26
26
  end
27
27
 
28
- should "be -1 for unique job" do
28
+ it "is -1 for unique job" do
29
29
  assert_equal -1, Queue.item_ttl(class: 'FakeUniqueJob')
30
30
  end
31
31
 
32
- should "be job TTL" do
32
+ it "is job TTL" do
33
33
  assert_equal 300, UniqueJobWithTtl.ttl
34
34
  assert_equal 300, Queue.item_ttl(class: 'UniqueJobWithTtl')
35
35
  end
36
36
  end
37
37
 
38
- context ".lock_after_execution_period" do
39
- should "be 0 for non-unique job" do
38
+ describe ".lock_after_execution_period" do
39
+ it "is 0 for non-unique job" do
40
40
  assert_equal 0, Queue.lock_after_execution_period(class: 'FakeJob')
41
41
  end
42
42
 
43
- should "be 0 for invalid job class" do
43
+ it "is 0 for invalid job class" do
44
44
  assert_equal 0, Queue.lock_after_execution_period(class: 'InvalidJob')
45
45
  end
46
46
 
47
- should "be 0 for unique job" do
47
+ it "is 0 for unique job" do
48
48
  assert_equal 0, Queue.lock_after_execution_period(class: 'FakeUniqueJob')
49
49
  end
50
50
 
51
- should "be job lock period" do
51
+ it "is job lock period" do
52
52
  assert_equal 150, UniqueJobWithLock.lock_after_execution_period
53
53
  assert_equal 150, Queue.lock_after_execution_period(class: 'UniqueJobWithLock')
54
54
  end
data/test/resque_test.rb CHANGED
@@ -1,30 +1,26 @@
1
1
  require 'test_helper'
2
2
 
3
- class ResqueTest < Test::Unit::TestCase
4
- setup do
3
+ class ResqueTest < MiniTest::Spec
4
+ before do
5
5
  Resque.redis.flushall
6
6
  end
7
7
 
8
- should "be a valid plugin" do
9
- assert_nothing_raised do
10
- Resque::Plugin.lint(Resque::Plugins::UniqueJob)
11
- end
8
+ it "is a valid plugin" do
9
+ Resque::Plugin.lint(Resque::Plugins::UniqueJob)
12
10
  end
13
11
 
14
- should "enqueue normal jobs" do
12
+ it "enqueues normal jobs" do
15
13
  Resque.enqueue FakeJob, "x"
16
14
  Resque.enqueue FakeJob, "x"
17
15
  assert_equal 2, Resque.size(:normal)
18
16
  end
19
17
 
20
- should "not be able to report if a non-unique job was enqueued" do
18
+ it "is not able to report if a non-unique job was enqueued" do
21
19
  assert_nil Resque.enqueued?(FakeJob)
22
20
  end
23
21
 
24
- should "not raise when deleting an empty queue" do
25
- assert_nothing_raised do
26
- Resque.remove_queue(:unique)
27
- end
22
+ it "does not raise when deleting an empty queue" do
23
+ Resque.remove_queue(:unique)
28
24
  end
29
25
 
30
- end
26
+ end
data/test/test_helper.rb CHANGED
@@ -3,13 +3,10 @@ if ENV['SIMPLE_COV']
3
3
  SimpleCov.start
4
4
  end
5
5
 
6
- require 'test/unit'
7
- require 'shoulda-context'
8
- require 'mocha/setup'
6
+ require 'minitest/autorun'
9
7
  require 'resque_solo'
10
8
  require 'fake_jobs'
11
9
  require 'fakeredis'
12
- require 'pry'
13
10
  begin
14
11
  require 'pry-byebug'
15
12
  rescue LoadError
@@ -1,5 +1,5 @@
1
1
  require 'test_helper'
2
2
 
3
- class UniqueJobTest < Test::Unit::TestCase
3
+ class UniqueJobTest < MiniTest::Spec
4
4
 
5
- end
5
+ end
metadata CHANGED
@@ -1,57 +1,85 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: resque_solo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tee Parham
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-17 00:00:00.000000000 Z
11
+ date: 2014-03-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: resque
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: 1.25.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: 1.25.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.3'
33
+ version: '1.5'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '1.3'
40
+ version: '1.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: fakeredis
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.4'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.4'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '5.3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '5.3'
41
69
  - !ruby/object:Gem::Dependency
42
70
  name: rake
43
71
  requirement: !ruby/object:Gem::Requirement
44
72
  requirements:
45
- - - '>='
73
+ - - "~>"
46
74
  - !ruby/object:Gem::Version
47
- version: '0'
75
+ version: '10.1'
48
76
  type: :development
49
77
  prerelease: false
50
78
  version_requirements: !ruby/object:Gem::Requirement
51
79
  requirements:
52
- - - '>='
80
+ - - "~>"
53
81
  - !ruby/object:Gem::Version
54
- version: '0'
82
+ version: '10.1'
55
83
  description: Resque plugin to add unique jobs
56
84
  email:
57
85
  - tee@neighborland.com
@@ -59,9 +87,9 @@ executables: []
59
87
  extensions: []
60
88
  extra_rdoc_files: []
61
89
  files:
62
- - .gitignore
63
- - .ruby-version
64
- - .travis.yml
90
+ - ".gitignore"
91
+ - ".ruby-version"
92
+ - ".travis.yml"
65
93
  - Gemfile
66
94
  - LICENSE.txt
67
95
  - README.md
@@ -89,17 +117,17 @@ require_paths:
89
117
  - lib
90
118
  required_ruby_version: !ruby/object:Gem::Requirement
91
119
  requirements:
92
- - - '>='
120
+ - - ">="
93
121
  - !ruby/object:Gem::Version
94
122
  version: 1.9.3
95
123
  required_rubygems_version: !ruby/object:Gem::Requirement
96
124
  requirements:
97
- - - '>='
125
+ - - ">="
98
126
  - !ruby/object:Gem::Version
99
127
  version: '0'
100
128
  requirements: []
101
129
  rubyforge_project:
102
- rubygems_version: 2.1.11
130
+ rubygems_version: 2.2.2
103
131
  signing_key:
104
132
  specification_version: 4
105
133
  summary: Resque plugin to add unique jobs
@@ -110,3 +138,4 @@ test_files:
110
138
  - test/resque_test.rb
111
139
  - test/test_helper.rb
112
140
  - test/unique_job_test.rb
141
+ has_rdoc: