restalk 0.0.0.14 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gemspec +1 -1
- data/Gemfile.lock +13 -13
- data/README.md +39 -13
- data/lib/restalk.rb +29 -16
- metadata +8 -7
data/.gemspec
CHANGED
@@ -13,7 +13,7 @@ Gem::Specification.new do |gem|
|
|
13
13
|
gem.homepage = 'http://github.com/undecisive/restalk'
|
14
14
|
|
15
15
|
#gem.add_development_dependency('rake')
|
16
|
-
gem.add_dependency('
|
16
|
+
gem.add_dependency('beaneater')
|
17
17
|
gem.add_dependency('resque', ['1.21.0'])
|
18
18
|
|
19
19
|
# ensure the gem is built out of versioned files
|
data/Gemfile.lock
CHANGED
@@ -1,31 +1,31 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
restalk (0.
|
5
|
-
|
4
|
+
restalk (0.1.0)
|
5
|
+
beaneater
|
6
6
|
resque (= 1.21.0)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: http://rubygems.org/
|
10
10
|
specs:
|
11
|
-
|
12
|
-
multi_json (1.
|
13
|
-
rack (1.
|
14
|
-
rack-protection (1.
|
11
|
+
beaneater (0.3.0)
|
12
|
+
multi_json (1.7.1)
|
13
|
+
rack (1.5.2)
|
14
|
+
rack-protection (1.5.0)
|
15
15
|
rack
|
16
|
-
redis (3.0.
|
17
|
-
redis-namespace (1.2.
|
16
|
+
redis (3.0.3)
|
17
|
+
redis-namespace (1.2.1)
|
18
18
|
redis (~> 3.0.0)
|
19
19
|
resque (1.21.0)
|
20
20
|
multi_json (~> 1.0)
|
21
21
|
redis-namespace (~> 1.0)
|
22
22
|
sinatra (>= 0.9.2)
|
23
23
|
vegas (~> 0.1.2)
|
24
|
-
sinatra (1.
|
25
|
-
rack (~> 1.
|
26
|
-
rack-protection (~> 1.
|
27
|
-
tilt (~> 1.3, >= 1.3.
|
28
|
-
tilt (1.3.
|
24
|
+
sinatra (1.4.1)
|
25
|
+
rack (~> 1.5, >= 1.5.2)
|
26
|
+
rack-protection (~> 1.4)
|
27
|
+
tilt (~> 1.3, >= 1.3.4)
|
28
|
+
tilt (1.3.6)
|
29
29
|
vegas (0.1.11)
|
30
30
|
rack (>= 1.0.0)
|
31
31
|
|
data/README.md
CHANGED
@@ -9,27 +9,53 @@ It has a very simple interface:
|
|
9
9
|
|
10
10
|
```ruby
|
11
11
|
Restalk.init(:resque) # Create a connection to the backend (in this case, resque)
|
12
|
-
Restalk.push(
|
13
|
-
Restalk.pop
|
12
|
+
Restalk.push("Hello") # Push something onto the queue
|
13
|
+
datum = Restalk.pop # Pop something off the queue. Returns instantly. Could be nil.
|
14
|
+
|
15
|
+
datum.body if datum # Get the actual value
|
14
16
|
|
15
17
|
Restalk.connected? # Test whether init has been called
|
16
18
|
Restalk.stats # Statistics (whatever the backend gives us - could be gibberish)
|
17
19
|
```
|
18
20
|
|
21
|
+
|
22
|
+
If you need both services, or different channels, or object orientation, we have you covered:
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
beanie = Restalk.new(:beanstalk, nil, 'jack') # nil for the server, uses the default
|
26
|
+
rezzer = Restalk.new(:resque, nil, 'funky_chicken')
|
27
|
+
|
28
|
+
item = beanie.pop
|
29
|
+
rezzer.push(item.body) if item
|
30
|
+
|
31
|
+
beanie.connected?
|
32
|
+
rezzer.stats
|
33
|
+
```
|
34
|
+
|
35
|
+
|
19
36
|
Configuration
|
20
37
|
-------------
|
21
38
|
|
22
39
|
Servers: Restalk defaults to '127.0.0.1:11300' for beanstalk and 'localhost:6379' for resque.
|
23
40
|
|
24
|
-
Queue: Restalk names the queue, highly imaginatively, 'restalk_queue'
|
41
|
+
Queue: Restalk, by default, names the queue, highly imaginatively, 'restalk_queue'.
|
42
|
+
Beanstalk does not seem to support named queues, so an exception will be raised if you try to set one.
|
25
43
|
|
26
|
-
These can be configured easily via environment variables
|
44
|
+
These can be configured easily via environment variables:
|
45
|
+
ENV['BEANSTALK'] - Beanstalk server address
|
46
|
+
ENV['BEANSTALK_QUEUE'] - Beanstalk tube name
|
47
|
+
|
48
|
+
ENV['REDIS'] - Redis server address
|
49
|
+
ENV['RESQUE_QUEUE'] - Resque queue name
|
50
|
+
|
51
|
+
All of these can be overridden on a per-instance basis.
|
27
52
|
|
28
53
|
|
29
54
|
Author
|
30
55
|
------
|
31
56
|
|
32
57
|
Matthew Bennett @undecisive [wearepandr.com](http://wearepandr.com)
|
58
|
+
|
33
59
|
Got a question? Message me on [Github](http://github.com/undecisive) or add an issue.
|
34
60
|
|
35
61
|
|
@@ -38,19 +64,19 @@ License
|
|
38
64
|
|
39
65
|
```
|
40
66
|
The MIT License (MIT)
|
41
|
-
Copyright (c) 2012 We are PANDR
|
67
|
+
Copyright (c) 2012-2013 We are PANDR
|
42
68
|
|
43
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
|
44
|
-
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
|
45
|
-
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
|
69
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
|
70
|
+
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
|
71
|
+
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
|
46
72
|
and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
47
73
|
|
48
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions
|
74
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions
|
49
75
|
of the Software.
|
50
76
|
|
51
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
52
|
-
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
53
|
-
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
54
|
-
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
77
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
78
|
+
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
79
|
+
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
80
|
+
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
55
81
|
IN THE SOFTWARE.
|
56
82
|
```
|
data/lib/restalk.rb
CHANGED
@@ -1,48 +1,61 @@
|
|
1
1
|
|
2
|
+
|
2
3
|
class Restalk
|
3
|
-
|
4
|
-
|
4
|
+
class RestalkBeanstalkException < StandardError; end
|
5
|
+
|
6
|
+
VERSION = '0.1.1'
|
7
|
+
def initialize(adapter, server=nil, queue=nil)
|
5
8
|
extend BeanstalkAdapter if adapter == :beanstalk
|
6
9
|
extend ResqueAdapter if [:resque, :redis].include? adapter
|
7
|
-
|
10
|
+
init server, queue
|
8
11
|
end
|
9
12
|
|
10
|
-
def
|
13
|
+
def connected?
|
11
14
|
self.respond_to? :push
|
12
15
|
end
|
13
|
-
|
16
|
+
|
17
|
+
def self.init(*args)
|
18
|
+
@current_adapter = self.new *args
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.method_missing(sym, *args, &block)
|
22
|
+
@current_adapter.send sym, *args, &block
|
23
|
+
end
|
24
|
+
|
14
25
|
module BeanstalkAdapter
|
15
|
-
def init
|
16
|
-
require '
|
17
|
-
|
26
|
+
def init(server = nil, queue = nil)
|
27
|
+
require 'beaneater'
|
28
|
+
@beanstalk = Beaneater::Pool.new([server || ENV['BEANSTALK'] || '127.0.0.1:11300'])
|
29
|
+
tube = queue || ENV['BEANSTALK_QUEUE'] || 'default'
|
30
|
+
@beanstalk = @beanstalk.tubes[tube]
|
18
31
|
end
|
19
32
|
|
20
33
|
def push(data)
|
21
|
-
|
34
|
+
@beanstalk.put(data)
|
22
35
|
end
|
23
36
|
|
24
37
|
def pop
|
25
|
-
|
38
|
+
@beanstalk.reserve if @beanstalk.peek(:ready)
|
26
39
|
end
|
27
40
|
|
28
41
|
def stats
|
29
|
-
|
42
|
+
@beanstalk.stats
|
30
43
|
end
|
31
44
|
end
|
32
45
|
|
33
46
|
module ResqueAdapter
|
34
|
-
|
35
|
-
|
47
|
+
def init(server = nil, queue = nil)
|
48
|
+
@queue = queue || ENV['RESQUE_QUEUE'] || 'restalk_queue'
|
36
49
|
require 'resque'
|
37
|
-
Resque.redis = ENV['REDIS'] || 'localhost:6379'
|
50
|
+
Resque.redis = server || ENV['REDIS'] || 'localhost:6379'
|
38
51
|
end
|
39
52
|
|
40
53
|
def push(data)
|
41
|
-
Resque.enqueue_to(
|
54
|
+
Resque.enqueue_to(@queue, RestalkResqueJob, data)
|
42
55
|
end
|
43
56
|
|
44
57
|
def pop
|
45
|
-
data = Resque.pop
|
58
|
+
data = Resque.pop @queue
|
46
59
|
return RestalkResqueJob.new data['args'].first if data
|
47
60
|
end
|
48
61
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: restalk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,24 +9,24 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-03-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
15
|
+
name: beaneater
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
|
-
- - '
|
19
|
+
- - ! '>='
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
21
|
+
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
none: false
|
26
26
|
requirements:
|
27
|
-
- - '
|
27
|
+
- - ! '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version:
|
29
|
+
version: '0'
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: resque
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
@@ -80,3 +80,4 @@ signing_key:
|
|
80
80
|
specification_version: 3
|
81
81
|
summary: Abstraction layer between Beanstalk / Resque
|
82
82
|
test_files: []
|
83
|
+
has_rdoc:
|