resque-remote-namespace 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +45 -0
- data/README.md +52 -0
- data/Rakefile +2 -0
- data/lib/resque-remote-namespace.rb +2 -0
- data/lib/resque-remote-namespace/remote_namespace.rb +41 -0
- data/lib/resque-remote-namespace/version.rb +7 -0
- data/resque-remote-namespace.gemspec +35 -0
- data/spec/remote_spec.rb +80 -0
- data/spec/spec_helper.rb +23 -0
- metadata +111 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
resque-remote-namespace (0.1.0)
|
5
|
+
resque (~> 1.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: http://rubygems.org/
|
9
|
+
specs:
|
10
|
+
diff-lcs (1.1.3)
|
11
|
+
multi_json (1.5.0)
|
12
|
+
rack (1.4.1)
|
13
|
+
rack-protection (1.3.2)
|
14
|
+
rack
|
15
|
+
redis (3.0.2)
|
16
|
+
redis-namespace (1.2.1)
|
17
|
+
redis (~> 3.0.0)
|
18
|
+
resque (1.23.0)
|
19
|
+
multi_json (~> 1.0)
|
20
|
+
redis-namespace (~> 1.0)
|
21
|
+
sinatra (>= 0.9.2)
|
22
|
+
vegas (~> 0.1.2)
|
23
|
+
rspec (2.8.0)
|
24
|
+
rspec-core (~> 2.8.0)
|
25
|
+
rspec-expectations (~> 2.8.0)
|
26
|
+
rspec-mocks (~> 2.8.0)
|
27
|
+
rspec-core (2.8.0)
|
28
|
+
rspec-expectations (2.8.0)
|
29
|
+
diff-lcs (~> 1.1.2)
|
30
|
+
rspec-mocks (2.8.0)
|
31
|
+
sinatra (1.3.3)
|
32
|
+
rack (~> 1.3, >= 1.3.6)
|
33
|
+
rack-protection (~> 1.2)
|
34
|
+
tilt (~> 1.3, >= 1.3.3)
|
35
|
+
tilt (1.3.3)
|
36
|
+
vegas (0.1.11)
|
37
|
+
rack (>= 1.0.0)
|
38
|
+
|
39
|
+
PLATFORMS
|
40
|
+
ruby
|
41
|
+
|
42
|
+
DEPENDENCIES
|
43
|
+
bundler (~> 1.0)
|
44
|
+
resque-remote-namespace!
|
45
|
+
rspec (~> 2.8)
|
data/README.md
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
`resque-remote-namespace` is a fork of the [remote-namespace gem](https://github.com/localshred/resque-remote) that allows for remote enqueueing and dequeueing of jobs on different redis namespaces.
|
2
|
+
|
3
|
+
# Installation
|
4
|
+
|
5
|
+
**Note: You must have a version of Resque installed or added to your Gemfile for `resque-remote-namespace` to work. Resque Version 0.10.0 has been tested to work with the current release of `resque-remote-namespace`.**
|
6
|
+
|
7
|
+
Add it to your Bundler `Gemfile`:
|
8
|
+
|
9
|
+
# Gemfile
|
10
|
+
gem 'resque', '0.10.0'
|
11
|
+
gem 'resque-remote-namespace', :git => 'git://github.com/lafave/resque-remote-namespace.git'
|
12
|
+
|
13
|
+
And then run a `bundle install`.
|
14
|
+
|
15
|
+
# Usage
|
16
|
+
|
17
|
+
## Enqueueing
|
18
|
+
```ruby
|
19
|
+
# Enqueues TestJob to the "default" queue on the "resque:foo" redis namespace with "foo" as its sole argument.
|
20
|
+
Resque.remote_enqueue_to 'default', 'resque:foo', 'TestJob', 'foo'
|
21
|
+
```
|
22
|
+
|
23
|
+
## Dequeueing
|
24
|
+
```ruby
|
25
|
+
# Dequeues TestJob from the "default" queue on the "resque:foo" redis namespace with "foo" as its sole argument
|
26
|
+
Resque.remote_dequeue_from 'default', 'resque:foo', 'TestJob', 'foo'
|
27
|
+
```
|
28
|
+
|
29
|
+
## Worker Processing
|
30
|
+
|
31
|
+
The job you are remotely enqueueing does not need to exist in the application you are in enqueueing it from, however if `Resque.inline` is set to `true` (as is often the case in a development or test environment) then Resque may attempt to execute the job in the current application, depending on which version of Resque you are using. This will cause a `NameError` to be raised.
|
32
|
+
|
33
|
+
To fix this, just create a stub of the job you are remote enqueueing. Ex:
|
34
|
+
```ruby
|
35
|
+
# Stub of TestJob. Actual implementation is located in X.
|
36
|
+
class TestJob
|
37
|
+
def self.perform(param1) end
|
38
|
+
end
|
39
|
+
```
|
40
|
+
|
41
|
+
Note that the actual implementation of the remote job does not need to have its `@queue` defined.
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
class TestJob
|
45
|
+
# no queue needed
|
46
|
+
|
47
|
+
def self.perform(param1)
|
48
|
+
...
|
49
|
+
end
|
50
|
+
end
|
51
|
+
```
|
52
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
module Resque
|
2
|
+
module Plugins
|
3
|
+
module RemoteNamespace
|
4
|
+
|
5
|
+
# Remote enqueue of a job by temporarily changing the Resque redis
|
6
|
+
# namespace.
|
7
|
+
#
|
8
|
+
# @param [ String ] queue The queue to enqueue the job to.
|
9
|
+
# @param [ String ] namespace The namespace to enqueue the job to.
|
10
|
+
# @param [ String ] klass The class name of the job to enqueue.
|
11
|
+
# @param [ Array ] args The arguments to the job being remotely enqueued.
|
12
|
+
def remote_enqueue_to(queue, namespace, klass, *args)
|
13
|
+
original_namespace = Resque.redis.namespace
|
14
|
+
Resque.redis.namespace = namespace
|
15
|
+
|
16
|
+
Resque::Job.create(queue.to_sym, klass, *args)
|
17
|
+
ensure
|
18
|
+
Resque.redis.namespace = original_namespace
|
19
|
+
end
|
20
|
+
|
21
|
+
# Remote dequeue of a job by temporarily changin gthe Resque redis
|
22
|
+
# namespace.
|
23
|
+
#
|
24
|
+
# @param [ String ] queue The queue to dequeue the job from.
|
25
|
+
# @param [ String ] namespace The namespace to dequeue the job from.
|
26
|
+
# @param [ String ] klass The class name of the job to enqueue.
|
27
|
+
# @param [ Array ] args The arguments to the job being remotely dequeued.
|
28
|
+
def remote_dequeue_from(queue, namespace, klass, *args)
|
29
|
+
original_namespace = Resque.redis.namespace
|
30
|
+
Resque.redis.namespace = namespace
|
31
|
+
|
32
|
+
Resque::Job.destroy(queue.to_sym, klass, *args)
|
33
|
+
ensure
|
34
|
+
Resque.redis.namespace = original_namespace
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# Pull the remote methods into the Resque module
|
40
|
+
extend Plugins::RemoteNamespace
|
41
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/resque-remote-namespace/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = 'resque-remote-namespace'
|
6
|
+
s.version = Resque::Plugins::RemoteNamespace::VERSION
|
7
|
+
s.platform = Gem::Platform::RUBY
|
8
|
+
s.authors = ['BJ Neilsen', 'Adam LaFave']
|
9
|
+
s.email = ['bj.neilsen@gmail.com', 'lafave.adam@gmail.com']
|
10
|
+
s.homepage = 'http://github.com/lafave/resque-remote-namespace'
|
11
|
+
s.summary = %Q{
|
12
|
+
Resque plugin to allow remote enqueueing and dequeueing of jobs across
|
13
|
+
different namespaces.
|
14
|
+
}
|
15
|
+
s.description = %Q{
|
16
|
+
Remotely enqueueing and dequeueing jobs across Redis namespaces should
|
17
|
+
be simpler. BJ Neilsen laid a solid foundation for this gem, which is
|
18
|
+
forked off of his gem resque-remote. That said, these two gems provide a
|
19
|
+
different set of methods for remote enqueueing and dequeueing.
|
20
|
+
|
21
|
+
If all you need is remote enqueueing within the same namespace, use
|
22
|
+
resque-remote.
|
23
|
+
}
|
24
|
+
|
25
|
+
s.required_rubygems_version = '>= 1.3.6'
|
26
|
+
s.rubyforge_project = 'resque-remote-namespace'
|
27
|
+
|
28
|
+
s.add_dependency 'resque', '~> 1.0'
|
29
|
+
|
30
|
+
s.add_development_dependency 'bundler', '~> 1.0'
|
31
|
+
s.add_development_dependency 'rspec', '~> 2.8'
|
32
|
+
|
33
|
+
s.files = `git ls-files`.split("\n")
|
34
|
+
s.require_path = 'lib'
|
35
|
+
end
|
data/spec/remote_spec.rb
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Resque::Plugins::RemoteNamespace do
|
4
|
+
let(:queue) { :default }
|
5
|
+
let(:remote_namespace) { 'resque:bar' }
|
6
|
+
|
7
|
+
before :each do
|
8
|
+
from_namespace remote_namespace do
|
9
|
+
Resque.remove_queue(queue)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'passes resque lint' do
|
14
|
+
lambda {
|
15
|
+
Resque::Plugin.lint(Resque::Plugins::RemoteNamespace)
|
16
|
+
}.should_not raise_error
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'response to remote_enqueue_to' do
|
20
|
+
Resque.should respond_to :remote_enqueue_to
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'response to remote_dequeue_from' do
|
24
|
+
Resque.should respond_to :remote_dequeue_from
|
25
|
+
end
|
26
|
+
|
27
|
+
describe '#remote_enqueue_to' do
|
28
|
+
subject { Resque.remote_enqueue_to queue, remote_namespace, 'TestJob', 'foo' }
|
29
|
+
|
30
|
+
it 'temporarily changes Resque.redis.namespace' do
|
31
|
+
Resque.redis.should_receive(:namespace=)
|
32
|
+
.with('resque:foo')
|
33
|
+
.once
|
34
|
+
|
35
|
+
Resque.redis.should_receive(:namespace=)
|
36
|
+
.with('resque:bar')
|
37
|
+
.once
|
38
|
+
|
39
|
+
subject
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'enqueues a job' do
|
43
|
+
expect {
|
44
|
+
subject
|
45
|
+
}.to change {
|
46
|
+
from_namespace remote_namespace do
|
47
|
+
Resque.size(queue)
|
48
|
+
end
|
49
|
+
}.from(0).to(1)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe '#remote_dequeue_from' do
|
54
|
+
subject { Resque.remote_dequeue_from queue, remote_namespace, 'TestJob', 'foo' }
|
55
|
+
|
56
|
+
it 'temporarily changes 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 'dequeues a job' do
|
69
|
+
Resque.remote_enqueue_to queue, remote_namespace, 'TestJob', 'foo'
|
70
|
+
|
71
|
+
expect {
|
72
|
+
subject
|
73
|
+
}.to change {
|
74
|
+
from_namespace remote_namespace do
|
75
|
+
Resque.size(queue)
|
76
|
+
end
|
77
|
+
}.from(1).to(0)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
3
|
+
require 'rspec'
|
4
|
+
|
5
|
+
$: << File.expand_path('../lib', File.dirname(__FILE__))
|
6
|
+
|
7
|
+
require 'resque-remote-namespace'
|
8
|
+
|
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
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: resque-remote-namespace
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- BJ Neilsen
|
9
|
+
- Adam LaFave
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2013-03-12 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: resque
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ~>
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '1.0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ~>
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: '1.0'
|
31
|
+
- !ruby/object:Gem::Dependency
|
32
|
+
name: bundler
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
35
|
+
requirements:
|
36
|
+
- - ~>
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '1.0'
|
39
|
+
type: :development
|
40
|
+
prerelease: false
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ~>
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '1.0'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rspec
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.8'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ~>
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '2.8'
|
63
|
+
description: ! "\n Remotely enqueueing and dequeueing jobs across Redis namespaces
|
64
|
+
should\n be simpler. BJ Neilsen laid a solid foundation for this gem, which is\n
|
65
|
+
\ forked off of his gem resque-remote. That said, these two gems provide a\n different
|
66
|
+
set of methods for remote enqueueing and dequeueing.\n\n If all you need is remote
|
67
|
+
enqueueing within the same namespace, use\n resque-remote.\n "
|
68
|
+
email:
|
69
|
+
- bj.neilsen@gmail.com
|
70
|
+
- lafave.adam@gmail.com
|
71
|
+
executables: []
|
72
|
+
extensions: []
|
73
|
+
extra_rdoc_files: []
|
74
|
+
files:
|
75
|
+
- .gitignore
|
76
|
+
- Gemfile
|
77
|
+
- Gemfile.lock
|
78
|
+
- README.md
|
79
|
+
- Rakefile
|
80
|
+
- lib/resque-remote-namespace.rb
|
81
|
+
- lib/resque-remote-namespace/remote_namespace.rb
|
82
|
+
- lib/resque-remote-namespace/version.rb
|
83
|
+
- resque-remote-namespace.gemspec
|
84
|
+
- spec/remote_spec.rb
|
85
|
+
- spec/spec_helper.rb
|
86
|
+
homepage: http://github.com/lafave/resque-remote-namespace
|
87
|
+
licenses: []
|
88
|
+
post_install_message:
|
89
|
+
rdoc_options: []
|
90
|
+
require_paths:
|
91
|
+
- lib
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
none: false
|
94
|
+
requirements:
|
95
|
+
- - ! '>='
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
|
+
none: false
|
100
|
+
requirements:
|
101
|
+
- - ! '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 1.3.6
|
104
|
+
requirements: []
|
105
|
+
rubyforge_project: resque-remote-namespace
|
106
|
+
rubygems_version: 1.8.23
|
107
|
+
signing_key:
|
108
|
+
specification_version: 3
|
109
|
+
summary: Resque plugin to allow remote enqueueing and dequeueing of jobs across different
|
110
|
+
namespaces.
|
111
|
+
test_files: []
|