resque-remote-namespace 0.1.0 → 0.2.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/Gemfile.lock +27 -11
- data/lib/resque-remote-namespace.rb +3 -1
- data/lib/resque-remote-namespace/remote_namespace.rb +42 -31
- data/lib/resque-remote-namespace/support/shared_helpers.rb +13 -0
- data/lib/resque-remote-namespace/version.rb +1 -1
- data/resque-remote-namespace.gemspec +2 -0
- data/spec/remote_spec.rb +26 -0
- data/spec/spec_helper.rb +0 -14
- metadata +35 -2
data/Gemfile.lock
CHANGED
@@ -1,25 +1,37 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
resque-remote-namespace (0.
|
4
|
+
resque-remote-namespace (0.2.0)
|
5
5
|
resque (~> 1.0)
|
6
|
+
resque-scheduler
|
6
7
|
|
7
8
|
GEM
|
8
9
|
remote: http://rubygems.org/
|
9
10
|
specs:
|
11
|
+
columnize (0.3.6)
|
12
|
+
debugger (1.5.0)
|
13
|
+
columnize (>= 0.3.1)
|
14
|
+
debugger-linecache (~> 1.2.0)
|
15
|
+
debugger-ruby_core_source (~> 1.2.0)
|
16
|
+
debugger-linecache (1.2.0)
|
17
|
+
debugger-ruby_core_source (1.2.0)
|
10
18
|
diff-lcs (1.1.3)
|
11
|
-
multi_json (1.
|
12
|
-
rack (1.
|
13
|
-
rack-protection (1.
|
19
|
+
multi_json (1.7.0)
|
20
|
+
rack (1.5.2)
|
21
|
+
rack-protection (1.5.0)
|
14
22
|
rack
|
15
|
-
redis (3.0.
|
23
|
+
redis (3.0.3)
|
16
24
|
redis-namespace (1.2.1)
|
17
25
|
redis (~> 3.0.0)
|
18
|
-
resque (1.23.
|
26
|
+
resque (1.23.1)
|
19
27
|
multi_json (~> 1.0)
|
20
28
|
redis-namespace (~> 1.0)
|
21
29
|
sinatra (>= 0.9.2)
|
22
30
|
vegas (~> 0.1.2)
|
31
|
+
resque-scheduler (2.0.0)
|
32
|
+
redis (>= 2.0.1)
|
33
|
+
resque (>= 1.20.0)
|
34
|
+
rufus-scheduler
|
23
35
|
rspec (2.8.0)
|
24
36
|
rspec-core (~> 2.8.0)
|
25
37
|
rspec-expectations (~> 2.8.0)
|
@@ -28,11 +40,14 @@ GEM
|
|
28
40
|
rspec-expectations (2.8.0)
|
29
41
|
diff-lcs (~> 1.1.2)
|
30
42
|
rspec-mocks (2.8.0)
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
43
|
+
rufus-scheduler (2.0.18)
|
44
|
+
tzinfo (>= 0.3.23)
|
45
|
+
sinatra (1.4.1)
|
46
|
+
rack (~> 1.5, >= 1.5.2)
|
47
|
+
rack-protection (~> 1.4)
|
48
|
+
tilt (~> 1.3, >= 1.3.4)
|
49
|
+
tilt (1.3.6)
|
50
|
+
tzinfo (0.3.37)
|
36
51
|
vegas (0.1.11)
|
37
52
|
rack (>= 1.0.0)
|
38
53
|
|
@@ -41,5 +56,6 @@ PLATFORMS
|
|
41
56
|
|
42
57
|
DEPENDENCIES
|
43
58
|
bundler (~> 1.0)
|
59
|
+
debugger
|
44
60
|
resque-remote-namespace!
|
45
61
|
rspec (~> 2.8)
|
@@ -1,41 +1,52 @@
|
|
1
1
|
module Resque
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
2
|
+
module Plugins
|
3
|
+
module RemoteNamespace
|
4
|
+
|
5
|
+
# Remote enqueue of a job by temporarily changing the Resque redis
|
6
6
|
# namespace.
|
7
7
|
#
|
8
8
|
# @param [ String ] queue The queue to enqueue the job to.
|
9
9
|
# @param [ String ] namespace The namespace to enqueue the job to.
|
10
10
|
# @param [ String ] klass The class name of the job to enqueue.
|
11
11
|
# @param [ Array ] args The arguments to the job being remotely enqueued.
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
def remote_enqueue_to(queue, namespace, klass, *args)
|
13
|
+
from_namespace(namespace) do
|
14
|
+
Resque::Job.create(queue.to_sym, klass, *args)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# Remote enqueue of a job in the future by temporarily changing the
|
19
|
+
# Resque redis namespace.
|
20
|
+
#
|
21
|
+
# @param [ String ] number_of_seconds_from_now The number of seconds from
|
22
|
+
# now to enqueue the job at.
|
23
|
+
# @param [ String ] queue The queue to enqueue the job to.
|
24
|
+
# @param [ String ] namespace The namespace to enqueue the job to.
|
25
|
+
# @param [ String ] klass The class name of the job to enqueue.
|
26
|
+
# @param [ Array ] args The arguments to the job being remotely enqueued.
|
27
|
+
def remote_enqueue_to_in(number_of_seconds_from_now, queue, namespace, klass, *args)
|
28
|
+
time_to_enqueue = Time.now + number_of_seconds_from_now
|
15
29
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
30
|
+
from_namespace(namespace) do
|
31
|
+
Resque.enqueue_at_with_queue(queue, time_to_enqueue, klass, *args)
|
32
|
+
end
|
33
|
+
end
|
20
34
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
35
|
+
# Remote dequeue of a job by temporarily changin gthe Resque redis
|
36
|
+
# namespace.
|
37
|
+
#
|
38
|
+
# @param [ String ] queue The queue to dequeue the job from.
|
39
|
+
# @param [ String ] namespace The namespace to dequeue the job from.
|
40
|
+
# @param [ String ] klass The class name of the job to enqueue.
|
41
|
+
# @param [ Array ] args The arguments to the job being remotely dequeued.
|
42
|
+
def remote_dequeue_from(queue, namespace, klass, *args)
|
43
|
+
from_namespace(namespace) do
|
44
|
+
Resque::Job.destroy(queue.to_sym, klass, *args)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
31
49
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
# Pull the remote methods into the Resque module
|
40
|
-
extend Plugins::RemoteNamespace
|
41
|
-
end
|
50
|
+
# Pull the remote methods into the Resque module
|
51
|
+
extend Plugins::RemoteNamespace
|
52
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# Run a block of code from a different namespace.
|
2
|
+
#
|
3
|
+
# @param [ String ] namespace The namespace to execute the block of code from.
|
4
|
+
# @param [ Proc ] block The block of code to execute from a different
|
5
|
+
# namespace.
|
6
|
+
def from_namespace(namespace, &block)
|
7
|
+
original_namespace = Resque.redis.namespace
|
8
|
+
Resque.redis.namespace = namespace
|
9
|
+
|
10
|
+
yield if block_given?
|
11
|
+
ensure
|
12
|
+
Resque.redis.namespace = original_namespace
|
13
|
+
end
|
@@ -26,8 +26,10 @@ Gem::Specification.new do |s|
|
|
26
26
|
s.rubyforge_project = 'resque-remote-namespace'
|
27
27
|
|
28
28
|
s.add_dependency 'resque', '~> 1.0'
|
29
|
+
s.add_dependency 'resque-scheduler'
|
29
30
|
|
30
31
|
s.add_development_dependency 'bundler', '~> 1.0'
|
32
|
+
s.add_development_dependency 'debugger'
|
31
33
|
s.add_development_dependency 'rspec', '~> 2.8'
|
32
34
|
|
33
35
|
s.files = `git ls-files`.split("\n")
|
data/spec/remote_spec.rb
CHANGED
@@ -50,6 +50,32 @@ describe Resque::Plugins::RemoteNamespace do
|
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
|
+
describe '#remote_enqueue_to_in' do
|
54
|
+
subject { Resque.remote_enqueue_to_in 5, queue, remote_namespace, 'TestJob', 'foo' }
|
55
|
+
|
56
|
+
it 'temporarily changes the Resque.redis.namespace' do
|
57
|
+
Resque.redis.should_receive(:namespace=)
|
58
|
+
.with('resque:foo')
|
59
|
+
.once
|
60
|
+
|
61
|
+
Resque.redis.should_receive(:namespace=)
|
62
|
+
.with('resque:bar')
|
63
|
+
.once
|
64
|
+
|
65
|
+
subject
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'enqueues a job' do
|
69
|
+
expect {
|
70
|
+
subject
|
71
|
+
}.to change {
|
72
|
+
from_namespace remote_namespace do
|
73
|
+
Resque.delayed_queue_schedule_size
|
74
|
+
end
|
75
|
+
}.by(1)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
53
79
|
describe '#remote_dequeue_from' do
|
54
80
|
subject { Resque.remote_dequeue_from queue, remote_namespace, 'TestJob', 'foo' }
|
55
81
|
|
data/spec/spec_helper.rb
CHANGED
@@ -7,17 +7,3 @@ $: << File.expand_path('../lib', File.dirname(__FILE__))
|
|
7
7
|
require 'resque-remote-namespace'
|
8
8
|
|
9
9
|
Resque.redis.namespace = 'resque:foo'
|
10
|
-
|
11
|
-
# Run a block of code from a different namespace.
|
12
|
-
#
|
13
|
-
# @param [ String ] namespace The namespace to execute the block of code from.
|
14
|
-
# @param [ Proc ] block The block of code to execute from a different
|
15
|
-
# namespace.
|
16
|
-
def from_namespace(namespace, &block)
|
17
|
-
original_namespace = Resque.redis.namespace
|
18
|
-
Resque.redis.namespace = namespace
|
19
|
-
|
20
|
-
yield if block_given?
|
21
|
-
ensure
|
22
|
-
Resque.redis.namespace = original_namespace
|
23
|
-
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: resque-remote-namespace
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-03-
|
13
|
+
date: 2013-03-21 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: resque
|
@@ -28,6 +28,22 @@ dependencies:
|
|
28
28
|
- - ~>
|
29
29
|
- !ruby/object:Gem::Version
|
30
30
|
version: '1.0'
|
31
|
+
- !ruby/object:Gem::Dependency
|
32
|
+
name: resque-scheduler
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
35
|
+
requirements:
|
36
|
+
- - ! '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
type: :runtime
|
40
|
+
prerelease: false
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
31
47
|
- !ruby/object:Gem::Dependency
|
32
48
|
name: bundler
|
33
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -44,6 +60,22 @@ dependencies:
|
|
44
60
|
- - ~>
|
45
61
|
- !ruby/object:Gem::Version
|
46
62
|
version: '1.0'
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
name: debugger
|
65
|
+
requirement: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ! '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
type: :development
|
72
|
+
prerelease: false
|
73
|
+
version_requirements: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ! '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
47
79
|
- !ruby/object:Gem::Dependency
|
48
80
|
name: rspec
|
49
81
|
requirement: !ruby/object:Gem::Requirement
|
@@ -79,6 +111,7 @@ files:
|
|
79
111
|
- Rakefile
|
80
112
|
- lib/resque-remote-namespace.rb
|
81
113
|
- lib/resque-remote-namespace/remote_namespace.rb
|
114
|
+
- lib/resque-remote-namespace/support/shared_helpers.rb
|
82
115
|
- lib/resque-remote-namespace/version.rb
|
83
116
|
- resque-remote-namespace.gemspec
|
84
117
|
- spec/remote_spec.rb
|