resque-assurances 0.0.0 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/{LICENSE.txt → LICENSE} +1 -1
- data/lib/resque-assurances.rb +31 -0
- data/lib/resque-assurances/job_key.rb +19 -0
- data/lib/resque-assurances/uniqueness.rb +23 -0
- data/lib/resque-assurances/version.rb +1 -1
- data/resque-assurances.gemspec +3 -3
- data/spec/lib/resque-assurances/job_key_spec.rb +21 -0
- data/spec/lib/resque-assurances/uniqueness_spec.rb +48 -0
- data/spec/spec_helper.rb +16 -0
- data/spec/support/another_unique_worker.rb +3 -0
- data/spec/support/test_worker.rb +15 -0
- data/spec/support/unique_worker.rb +3 -0
- metadata +27 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c296188518096f9c7d0eef7dbb63132cb4bbfa54
|
4
|
+
data.tar.gz: 96f7d16922cbe2a37ec418f3e7f8c16b011df1c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dd6a301c7bae1069638bc2e9893f56044abcf35fe7384cec98e5aca1b750fd1687e214c6236d569ad045576d585cbbb6e3aca23eac8fa832f04f37767b077448
|
7
|
+
data.tar.gz: b05eb5cc3fc367f87965ceb4129b8fa5f67506f065f26f77b69ac47be0db5225e4987a49436a44b4d03ebe05ed29d27747728be85564aa0562b31aec71416063
|
data/{LICENSE.txt → LICENSE}
RENAMED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'resque'
|
2
|
+
require_relative 'resque-assurances/uniqueness'
|
3
|
+
require_relative 'resque-assurances/job_key'
|
4
|
+
|
5
|
+
module Resque
|
6
|
+
module Assurances
|
7
|
+
REDIS_UNIQUENESS_KEY = 'resque:assurances:uniqueness'
|
8
|
+
|
9
|
+
class << self
|
10
|
+
def reset!
|
11
|
+
redis.del(REDIS_UNIQUENESS_KEY)
|
12
|
+
end
|
13
|
+
|
14
|
+
def unique?(key)
|
15
|
+
!redis.sismember(REDIS_UNIQUENESS_KEY, key)
|
16
|
+
end
|
17
|
+
|
18
|
+
def set_key(key)
|
19
|
+
redis.sadd(REDIS_UNIQUENESS_KEY, key)
|
20
|
+
end
|
21
|
+
|
22
|
+
def remove_key(key)
|
23
|
+
redis.srem(REDIS_UNIQUENESS_KEY, key)
|
24
|
+
end
|
25
|
+
|
26
|
+
def redis
|
27
|
+
Resque.redis
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Resque
|
2
|
+
module Assurances
|
3
|
+
class JobKey
|
4
|
+
def initialize(worker, *args)
|
5
|
+
@shash = generate_key(worker, *args)
|
6
|
+
end
|
7
|
+
|
8
|
+
def to_s
|
9
|
+
@shash
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def generate_key(*args)
|
15
|
+
Digest::MD5.hexdigest(Resque.encode(args))
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Resque
|
2
|
+
module Assurances
|
3
|
+
module Uniqueness
|
4
|
+
def before_enqueue_save_job_key(*args)
|
5
|
+
key = Resque::Assurances::JobKey.new(self, args)
|
6
|
+
|
7
|
+
if Resque::Assurances.unique?(key)
|
8
|
+
Resque::Assurances.set_key(key)
|
9
|
+
true
|
10
|
+
else
|
11
|
+
false
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def around_perform_remove_job_key(*args)
|
16
|
+
key = Resque::Assurances::JobKey.new(self, args)
|
17
|
+
yield *args
|
18
|
+
ensure
|
19
|
+
Resque::Assurances.remove_key(key)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/resque-assurances.gemspec
CHANGED
@@ -15,9 +15,9 @@ Gem::Specification.new do |s|
|
|
15
15
|
s.description = 'Collection of resque plugins that individually provide specific assurances about how resque workers will behave.'
|
16
16
|
|
17
17
|
s.files = `git ls-files`.split("\n")
|
18
|
-
s.test_files = `git ls-files -- spec/*`.split("n")
|
18
|
+
s.test_files = `git ls-files -- spec/*`.split("\n")
|
19
19
|
|
20
20
|
s.add_runtime_dependency 'resque', '>= 1.0', '< 2'
|
21
|
-
s.add_development_dependency 'rspec'
|
22
|
-
s.add_development_dependency 'resque_spec'
|
21
|
+
s.add_development_dependency 'rspec', '~> 3.0'
|
22
|
+
s.add_development_dependency 'resque_spec', '~> 0.16'
|
23
23
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Resque::Assurances::JobKey do
|
4
|
+
it 'generates a unique key from different payloads' do
|
5
|
+
key1 = described_class.new(TestWorker, [42])
|
6
|
+
key2 = described_class.new(TestWorker, [43])
|
7
|
+
expect(key1.to_s).to_not eq key2.to_s
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'generates a unique key from different worker classes' do
|
11
|
+
key1 = described_class.new(TestWorker, [42])
|
12
|
+
key2 = described_class.new(UniqueWorker, [42])
|
13
|
+
expect(key1.to_s).to_not eq key2.to_s
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'generates the same key when worker and payloads are the same' do
|
17
|
+
key1 = described_class.new(TestWorker, [42])
|
18
|
+
key2 = described_class.new(TestWorker, [42])
|
19
|
+
expect(key1.to_s).to eq key2.to_s
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Resque::Assurances::Uniqueness do
|
4
|
+
it 'enqueues workers once' do
|
5
|
+
2.times { Resque.enqueue(UniqueWorker, 42) }
|
6
|
+
expect(UniqueWorker).to have_queue_size_of(1)
|
7
|
+
expect(UniqueWorker).to have_queued(42)
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'enqueues workers without args once' do
|
11
|
+
2.times { Resque.enqueue(UniqueWorker) }
|
12
|
+
expect(UniqueWorker).to have_queue_size_of(1)
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'enqueues workers with different args' do
|
16
|
+
Resque.enqueue(UniqueWorker, 42)
|
17
|
+
Resque.enqueue(UniqueWorker, 43)
|
18
|
+
expect(UniqueWorker).to have_queue_size_of(2)
|
19
|
+
expect(UniqueWorker).to have_queued(42)
|
20
|
+
expect(UniqueWorker).to have_queued(43)
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'enqueues different workers with the same args' do
|
24
|
+
Resque.enqueue(UniqueWorker, 42)
|
25
|
+
Resque.enqueue(AnotherUniqueWorker, 42)
|
26
|
+
expect(UniqueWorker).to have_queued(42)
|
27
|
+
expect(AnotherUniqueWorker).to have_queued(42)
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'can be queued again after the work is performed' do
|
31
|
+
Resque.enqueue(UniqueWorker)
|
32
|
+
expect(UniqueWorker).to have_queue_size_of(1)
|
33
|
+
ResqueSpec.perform_all(UniqueWorker.queue)
|
34
|
+
expect(UniqueWorker).to have_queue_size_of(0)
|
35
|
+
Resque.enqueue(UniqueWorker)
|
36
|
+
expect(UniqueWorker).to have_queue_size_of(1)
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'can be queued again if the work fails' do
|
40
|
+
Resque.enqueue(UniqueWorker, 42)
|
41
|
+
expect(UniqueWorker).to have_queue_size_of(1)
|
42
|
+
expect(UniqueWorker).to receive(:do_some_work).and_raise(StandardError)
|
43
|
+
ResqueSpec.perform_all(UniqueWorker.queue) rescue StandardError
|
44
|
+
expect(UniqueWorker).to have_queue_size_of(0)
|
45
|
+
Resque.enqueue(UniqueWorker)
|
46
|
+
expect(UniqueWorker).to have_queue_size_of(1)
|
47
|
+
end
|
48
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
Bundler.setup
|
3
|
+
require 'resque-assurances'
|
4
|
+
require 'resque_spec'
|
5
|
+
require_relative 'support/test_worker'
|
6
|
+
require_relative 'support/unique_worker'
|
7
|
+
require_relative 'support/another_unique_worker'
|
8
|
+
|
9
|
+
Resque.redis.namespace = 'resque:test'
|
10
|
+
|
11
|
+
RSpec.configure do |config|
|
12
|
+
config.before(:each) do
|
13
|
+
ResqueSpec.reset!
|
14
|
+
Resque::Assurances.reset!
|
15
|
+
end
|
16
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: resque-assurances
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathan Fixler
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-06-
|
11
|
+
date: 2014-06-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: resque
|
@@ -34,30 +34,30 @@ dependencies:
|
|
34
34
|
name: rspec
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
36
36
|
requirements:
|
37
|
-
- - "
|
37
|
+
- - "~>"
|
38
38
|
- !ruby/object:Gem::Version
|
39
|
-
version: '0'
|
39
|
+
version: '3.0'
|
40
40
|
type: :development
|
41
41
|
prerelease: false
|
42
42
|
version_requirements: !ruby/object:Gem::Requirement
|
43
43
|
requirements:
|
44
|
-
- - "
|
44
|
+
- - "~>"
|
45
45
|
- !ruby/object:Gem::Version
|
46
|
-
version: '0'
|
46
|
+
version: '3.0'
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: resque_spec
|
49
49
|
requirement: !ruby/object:Gem::Requirement
|
50
50
|
requirements:
|
51
|
-
- - "
|
51
|
+
- - "~>"
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version: '0'
|
53
|
+
version: '0.16'
|
54
54
|
type: :development
|
55
55
|
prerelease: false
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
57
|
requirements:
|
58
|
-
- - "
|
58
|
+
- - "~>"
|
59
59
|
- !ruby/object:Gem::Version
|
60
|
-
version: '0'
|
60
|
+
version: '0.16'
|
61
61
|
description: Collection of resque plugins that individually provide specific assurances
|
62
62
|
about how resque workers will behave.
|
63
63
|
email:
|
@@ -69,10 +69,19 @@ files:
|
|
69
69
|
- ".gitignore"
|
70
70
|
- ".ruby-version"
|
71
71
|
- Gemfile
|
72
|
-
- LICENSE
|
72
|
+
- LICENSE
|
73
73
|
- README.md
|
74
|
+
- lib/resque-assurances.rb
|
75
|
+
- lib/resque-assurances/job_key.rb
|
76
|
+
- lib/resque-assurances/uniqueness.rb
|
74
77
|
- lib/resque-assurances/version.rb
|
75
78
|
- resque-assurances.gemspec
|
79
|
+
- spec/lib/resque-assurances/job_key_spec.rb
|
80
|
+
- spec/lib/resque-assurances/uniqueness_spec.rb
|
81
|
+
- spec/spec_helper.rb
|
82
|
+
- spec/support/another_unique_worker.rb
|
83
|
+
- spec/support/test_worker.rb
|
84
|
+
- spec/support/unique_worker.rb
|
76
85
|
homepage: https://rubygems.org/gems/resque-assurances
|
77
86
|
licenses:
|
78
87
|
- MIT
|
@@ -97,4 +106,10 @@ rubygems_version: 2.2.2
|
|
97
106
|
signing_key:
|
98
107
|
specification_version: 4
|
99
108
|
summary: Provide assurances for resque jobs.
|
100
|
-
test_files:
|
109
|
+
test_files:
|
110
|
+
- spec/lib/resque-assurances/job_key_spec.rb
|
111
|
+
- spec/lib/resque-assurances/uniqueness_spec.rb
|
112
|
+
- spec/spec_helper.rb
|
113
|
+
- spec/support/another_unique_worker.rb
|
114
|
+
- spec/support/test_worker.rb
|
115
|
+
- spec/support/unique_worker.rb
|