skein 0.3.2 → 0.3.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +17 -18
- data/LICENSE.md +20 -0
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/lib/skein/client.rb +5 -4
- data/lib/skein/client/subscriber.rb +5 -3
- data/lib/skein/client/worker.rb +60 -14
- data/skein.gemspec +7 -4
- data/test/script/em_example +52 -2
- data/test/unit/test_skein_client.rb +6 -6
- data/test/unit/test_skein_worker.rb +16 -0
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ff3221a3eff25a91df8e35a5c1fbcc7aa220c6c3
|
4
|
+
data.tar.gz: 390343d71f7ab2e9a3f854463a5533f009f8c618
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f89a9dbacd906a33742294cb909097d213ce7f4d6318aba28df1bb151a9fe6256d91b1b84454a1fc2e7fe1a3b70b08bc966ecae8ff6329e2f40824d062ddb996
|
7
|
+
data.tar.gz: 57754a31620ec832354dba43ca9387fe75c2e91fc7d8d44ac4c45a90f9e5f0dd7a4650d9a34c5fbab6140aec95501f8eb26d2258510d74809f85831993ac5e6c
|
data/Gemfile.lock
CHANGED
@@ -4,7 +4,7 @@ GEM
|
|
4
4
|
addressable (2.5.0)
|
5
5
|
public_suffix (~> 2.0, >= 2.0.2)
|
6
6
|
birling (0.1.3)
|
7
|
-
builder (3.2.
|
7
|
+
builder (3.2.3)
|
8
8
|
descendants_tracker (0.0.4)
|
9
9
|
thread_safe (~> 0.3, >= 0.3.1)
|
10
10
|
faraday (0.9.2)
|
@@ -18,45 +18,44 @@ GEM
|
|
18
18
|
multi_json (>= 1.7.5, < 2.0)
|
19
19
|
nokogiri (~> 1.6.0)
|
20
20
|
oauth2
|
21
|
-
hashie (3.
|
21
|
+
hashie (3.5.5)
|
22
22
|
highline (1.7.8)
|
23
|
-
jeweler (2.
|
23
|
+
jeweler (2.3.3)
|
24
24
|
builder
|
25
25
|
bundler (>= 1.0)
|
26
26
|
git (>= 1.2.5)
|
27
27
|
github_api (~> 0.11.0)
|
28
28
|
highline (>= 1.6.15)
|
29
29
|
nokogiri (>= 1.5.10)
|
30
|
+
psych (~> 2.2)
|
30
31
|
rake
|
31
32
|
rdoc
|
32
|
-
|
33
|
+
semver2
|
33
34
|
jwt (1.5.6)
|
34
35
|
mini_portile2 (2.1.0)
|
35
36
|
multi_json (1.12.1)
|
36
|
-
multi_xml (0.
|
37
|
+
multi_xml (0.6.0)
|
37
38
|
multipart-post (2.0.0)
|
38
39
|
nokogiri (1.6.8.1)
|
39
40
|
mini_portile2 (~> 2.1.0)
|
40
|
-
|
41
|
-
|
42
|
-
faraday (>= 0.8, < 0.10)
|
41
|
+
oauth2 (1.3.0)
|
42
|
+
faraday (>= 0.8, < 0.11)
|
43
43
|
jwt (~> 1.0)
|
44
44
|
multi_json (~> 1.3)
|
45
45
|
multi_xml (~> 0.5)
|
46
46
|
rack (>= 1.2, < 3)
|
47
|
-
power_assert (0.
|
48
|
-
|
47
|
+
power_assert (1.0.1)
|
48
|
+
psych (2.2.4)
|
49
|
+
public_suffix (2.0.5)
|
49
50
|
rack (2.0.1)
|
50
|
-
rake (
|
51
|
-
rdoc (5.
|
52
|
-
|
53
|
-
test-unit (3.2.
|
51
|
+
rake (12.0.0)
|
52
|
+
rdoc (5.1.0)
|
53
|
+
semver2 (3.4.2)
|
54
|
+
test-unit (3.2.3)
|
54
55
|
power_assert
|
55
|
-
thread_safe (0.3.
|
56
|
-
thread_safe (0.3.5-java)
|
56
|
+
thread_safe (0.3.6)
|
57
57
|
|
58
58
|
PLATFORMS
|
59
|
-
java
|
60
59
|
ruby
|
61
60
|
|
62
61
|
DEPENDENCIES
|
@@ -66,4 +65,4 @@ DEPENDENCIES
|
|
66
65
|
test-unit
|
67
66
|
|
68
67
|
BUNDLED WITH
|
69
|
-
1.
|
68
|
+
1.14.5
|
data/LICENSE.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2016 Scott Tadman, PostageApp
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
CHANGED
@@ -9,7 +9,7 @@ require 'jeweler'
|
|
9
9
|
Jeweler::Tasks.new do |gem|
|
10
10
|
gem.name = 'skein'
|
11
11
|
gem.homepage = 'http://github.com/postageapp/skein'
|
12
|
-
gem.license = '
|
12
|
+
gem.license = 'MIT'
|
13
13
|
gem.summary = %Q{RabbitMQ RPC/PubSub Library}
|
14
14
|
gem.description = %Q{Wrapper for RabbitMQ that makes blocking RPC calls and handles pub-sub broadcasts.}
|
15
15
|
gem.email = 'tadman@postageapp.com'
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.5
|
data/lib/skein/client.rb
CHANGED
@@ -10,8 +10,8 @@ class Skein::Client < Skein::Connected
|
|
10
10
|
new.rpc(*args)
|
11
11
|
end
|
12
12
|
|
13
|
-
def self.
|
14
|
-
new.
|
13
|
+
def self.worker(*args)
|
14
|
+
new.worker(*args)
|
15
15
|
end
|
16
16
|
|
17
17
|
def self.publisher(*args)
|
@@ -37,8 +37,9 @@ class Skein::Client < Skein::Connected
|
|
37
37
|
)
|
38
38
|
end
|
39
39
|
|
40
|
-
def
|
41
|
-
Skein::Client::
|
40
|
+
def worker(queue_name)
|
41
|
+
Skein::Client::Worker.new(
|
42
|
+
queue_name,
|
42
43
|
connection: self.connection,
|
43
44
|
context: self.context
|
44
45
|
)
|
@@ -16,16 +16,18 @@ class Skein::Client::Subscriber < Skein::Connected
|
|
16
16
|
@subscribe_queue.bind(@exchange, routing_key: routing_key)
|
17
17
|
end
|
18
18
|
|
19
|
-
def listen
|
19
|
+
def listen(block = true)
|
20
20
|
case (@subscribe_queue.class.to_s.split(/::/)[0])
|
21
21
|
when 'Bunny'
|
22
|
-
@subscribe_queue.subscribe(block:
|
22
|
+
@subscribe_queue.subscribe(block: block) do |delivery_info, properties, payload|
|
23
23
|
yield(JSON.load(payload), delivery_info, properties)
|
24
24
|
end
|
25
25
|
when 'MarchHare'
|
26
|
-
@subscribe_queue.subscribe(block:
|
26
|
+
@subscribe_queue.subscribe(block: block) do |metadata, payload|
|
27
27
|
yield(JSON.load(payload), metadata)
|
28
28
|
end
|
29
|
+
else
|
30
|
+
raise "Unknown queue type #{@subscribe_queue.class}, cannot listen."
|
29
31
|
end
|
30
32
|
end
|
31
33
|
end
|
data/lib/skein/client/worker.rb
CHANGED
@@ -3,7 +3,7 @@ require 'json'
|
|
3
3
|
class Skein::Client::Worker < Skein::Connected
|
4
4
|
# == Instance Methods =====================================================
|
5
5
|
|
6
|
-
def initialize(queue_name, exchange_name: nil, connection: nil, context: nil)
|
6
|
+
def initialize(queue_name, exchange_name: nil, connection: nil, context: nil, concurrency: nil)
|
7
7
|
super(connection: connection, context: context)
|
8
8
|
|
9
9
|
lock do
|
@@ -17,36 +17,82 @@ class Skein::Client::Worker < Skein::Connected
|
|
17
17
|
end
|
18
18
|
|
19
19
|
@handler = Skein::Handler.for(self)
|
20
|
+
@received = Queue.new
|
21
|
+
@replies = Queue.new
|
22
|
+
@concurrency = concurrency && concurrency.to_i || 1
|
23
|
+
@threads = [ ]
|
20
24
|
|
21
|
-
@
|
25
|
+
@threads << Thread.new do
|
22
26
|
Thread.abort_on_exception = true
|
23
27
|
|
24
28
|
Skein::Adapter.subscribe(@queue) do |payload, delivery_tag, reply_to|
|
25
|
-
@
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
29
|
+
@received << [ payload, delivery_tag, reply_to ]
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
@threads << Thread.new do
|
34
|
+
Thread.abort_on_exception = true
|
35
|
+
|
36
|
+
loop do
|
37
|
+
payload, delivery_tag, reply_to, reply_json = @replies.pop
|
38
|
+
|
39
|
+
channel.acknowledge(delivery_tag, true)
|
40
|
+
|
41
|
+
if (reply_to)
|
42
|
+
@reply_exchange.publish(
|
43
|
+
reply_json,
|
44
|
+
routing_key: reply_to,
|
45
|
+
content_type: 'application/json'
|
46
|
+
)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
@concurrency.times do
|
52
|
+
@threads << Thread.new do
|
53
|
+
Thread.abort_on_exception = true
|
54
|
+
|
55
|
+
loop do
|
56
|
+
payload, delivery_tag, reply_to = @received.pop
|
57
|
+
thread = Thread.current
|
58
|
+
|
59
|
+
@handler.handle(payload) do |reply_json|
|
60
|
+
@replies << [ payload, delivery_tag, reply_to, reply_json ]
|
61
|
+
|
62
|
+
if (thread == Thread.current)
|
63
|
+
thread = nil
|
64
|
+
else
|
65
|
+
thread.wakeup
|
66
|
+
end
|
34
67
|
end
|
68
|
+
|
69
|
+
thread and Thread.stop
|
35
70
|
end
|
36
71
|
end
|
37
72
|
end
|
38
73
|
end
|
74
|
+
|
75
|
+
self.after_initialize
|
76
|
+
end
|
77
|
+
|
78
|
+
# Extend this in derived classes to implement any desired customization to
|
79
|
+
# be performed after initialization
|
80
|
+
def after_initialize
|
39
81
|
end
|
40
82
|
|
41
83
|
def close
|
42
|
-
@thread
|
43
|
-
|
84
|
+
@threads.each do |thread|
|
85
|
+
thread.kill
|
86
|
+
thread.join
|
87
|
+
end
|
44
88
|
|
45
89
|
super
|
46
90
|
end
|
47
91
|
|
48
92
|
def join
|
49
|
-
@
|
93
|
+
@threads.each do |thread|
|
94
|
+
thread.join
|
95
|
+
end
|
50
96
|
end
|
51
97
|
|
52
98
|
def async?
|
data/skein.gemspec
CHANGED
@@ -2,25 +2,27 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: skein 0.3.
|
5
|
+
# stub: skein 0.3.5 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "skein".freeze
|
9
|
-
s.version = "0.3.
|
9
|
+
s.version = "0.3.5"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib".freeze]
|
13
13
|
s.authors = ["Scott Tadman".freeze]
|
14
|
-
s.date = "
|
14
|
+
s.date = "2017-03-20"
|
15
15
|
s.description = "Wrapper for RabbitMQ that makes blocking RPC calls and handles pub-sub broadcasts.".freeze
|
16
16
|
s.email = "tadman@postageapp.com".freeze
|
17
17
|
s.executables = ["skein".freeze]
|
18
18
|
s.extra_rdoc_files = [
|
19
|
+
"LICENSE.md",
|
19
20
|
"README.md"
|
20
21
|
]
|
21
22
|
s.files = [
|
22
23
|
"Gemfile",
|
23
24
|
"Gemfile.lock",
|
25
|
+
"LICENSE.md",
|
24
26
|
"README.md",
|
25
27
|
"RELEASES.md",
|
26
28
|
"Rakefile",
|
@@ -65,10 +67,11 @@ Gem::Specification.new do |s|
|
|
65
67
|
"test/unit/test_skein_rpc_error.rb",
|
66
68
|
"test/unit/test_skein_rpc_request.rb",
|
67
69
|
"test/unit/test_skein_support.rb",
|
70
|
+
"test/unit/test_skein_worker.rb",
|
68
71
|
"tmp/.gitignore"
|
69
72
|
]
|
70
73
|
s.homepage = "http://github.com/postageapp/skein".freeze
|
71
|
-
s.licenses = ["
|
74
|
+
s.licenses = ["MIT".freeze]
|
72
75
|
s.rubygems_version = "2.5.2".freeze
|
73
76
|
s.summary = "RabbitMQ RPC/PubSub Library".freeze
|
74
77
|
|
data/test/script/em_example
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
require 'rubygems'
|
4
|
+
require 'optparse'
|
4
5
|
|
5
6
|
gem 'eventmachine'
|
6
7
|
require 'eventmachine'
|
@@ -12,8 +13,25 @@ require 'skein'
|
|
12
13
|
# == Support Classes ========================================================
|
13
14
|
|
14
15
|
class EchoWorker < Skein::Client::Worker
|
16
|
+
def initialize(*args, concurrency: nil, delay: nil, wait: false, verbose: false)
|
17
|
+
super(*args, concurrency: concurrency)
|
18
|
+
|
19
|
+
@delay = delay || 0.0
|
20
|
+
@wait = false
|
21
|
+
end
|
22
|
+
|
15
23
|
def echo(*args)
|
16
|
-
|
24
|
+
if (@delay > 0)
|
25
|
+
EventMachine::Timer.new(self.delay) do
|
26
|
+
yield(*args)
|
27
|
+
end
|
28
|
+
elsif (@wait)
|
29
|
+
EventMachine.next_tick do
|
30
|
+
yield(*args)
|
31
|
+
end
|
32
|
+
else
|
33
|
+
yield(*args)
|
34
|
+
end
|
17
35
|
end
|
18
36
|
|
19
37
|
def async?
|
@@ -23,6 +41,38 @@ end
|
|
23
41
|
|
24
42
|
# == Main ===================================================================
|
25
43
|
|
44
|
+
options = {
|
45
|
+
concurrency: 1,
|
46
|
+
delay: 0.0,
|
47
|
+
wait: false,
|
48
|
+
verbose: false
|
49
|
+
}
|
50
|
+
|
51
|
+
parser = OptionParser.new do |parser|
|
52
|
+
parser.on('-v', '--verbose') do
|
53
|
+
options[:verbose] = true
|
54
|
+
end
|
55
|
+
|
56
|
+
parser.on('-d', '--delay=n') do |n|
|
57
|
+
options[:delay] = n.to_f
|
58
|
+
end
|
59
|
+
|
60
|
+
parser.on('-c', '--concurrency=n') do |n|
|
61
|
+
options[:concurrency] = n.to_i
|
62
|
+
end
|
63
|
+
|
64
|
+
parser.on('-w', '--wait') do
|
65
|
+
options[:wait] = true
|
66
|
+
end
|
67
|
+
|
68
|
+
parser.on('-h', '--help') do
|
69
|
+
puts parser
|
70
|
+
exit(0)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
args = parser.parse(*ARGV)
|
75
|
+
|
26
76
|
EventMachine.run do
|
27
|
-
EchoWorker.new('test_echo')
|
77
|
+
worker = EchoWorker.new('test_echo', options)
|
28
78
|
end
|
@@ -5,14 +5,14 @@ class TestSkeinClient < Test::Unit::TestCase
|
|
5
5
|
client = nil
|
6
6
|
|
7
7
|
assert_no_threads do
|
8
|
-
|
8
|
+
begin
|
9
|
+
client = Skein::Client.new
|
9
10
|
|
10
|
-
|
11
|
+
assert client.context
|
11
12
|
|
12
|
-
|
13
|
+
ensure
|
14
|
+
client and client.close
|
15
|
+
end
|
13
16
|
end
|
14
|
-
|
15
|
-
# ensure
|
16
|
-
# client and client.close
|
17
17
|
end
|
18
18
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require_relative '../helper'
|
2
|
+
|
3
|
+
class TestSkeinWorker < Test::Unit::TestCase
|
4
|
+
def test_default
|
5
|
+
client = Skein::Client.new
|
6
|
+
|
7
|
+
worker = client.worker('test_queue')
|
8
|
+
|
9
|
+
assert worker
|
10
|
+
|
11
|
+
assert_equal false, worker.async?
|
12
|
+
|
13
|
+
ensure
|
14
|
+
client and client.close
|
15
|
+
end
|
16
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: skein
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Scott Tadman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-03-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: birling
|
@@ -73,10 +73,12 @@ executables:
|
|
73
73
|
- skein
|
74
74
|
extensions: []
|
75
75
|
extra_rdoc_files:
|
76
|
+
- LICENSE.md
|
76
77
|
- README.md
|
77
78
|
files:
|
78
79
|
- Gemfile
|
79
80
|
- Gemfile.lock
|
81
|
+
- LICENSE.md
|
80
82
|
- README.md
|
81
83
|
- RELEASES.md
|
82
84
|
- Rakefile
|
@@ -121,10 +123,11 @@ files:
|
|
121
123
|
- test/unit/test_skein_rpc_error.rb
|
122
124
|
- test/unit/test_skein_rpc_request.rb
|
123
125
|
- test/unit/test_skein_support.rb
|
126
|
+
- test/unit/test_skein_worker.rb
|
124
127
|
- tmp/.gitignore
|
125
128
|
homepage: http://github.com/postageapp/skein
|
126
129
|
licenses:
|
127
|
-
-
|
130
|
+
- MIT
|
128
131
|
metadata: {}
|
129
132
|
post_install_message:
|
130
133
|
rdoc_options: []
|