asir 0.2.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -2
- data/README.textile +4 -2
- data/VERSION +1 -1
- data/asir.gemspec +1 -4
- data/asir.riterate.yml +1 -0
- data/bin/asir +2 -1
- data/example/asir_control.sh +63 -1
- data/example/asir_control_client_http.rb +2 -2
- data/example/asir_control_client_resque.rb +16 -0
- data/example/asir_control_client_zmq.rb +3 -3
- data/example/config/asir_config.rb +20 -8
- data/example/ex02.rb +1 -1
- data/example/ex03.rb +2 -2
- data/example/ex04.rb +2 -2
- data/example/ex05.rb +1 -1
- data/example/ex06.rb +6 -5
- data/example/ex07.rb +2 -2
- data/example/ex08.rb +2 -2
- data/example/ex09.rb +2 -2
- data/example/ex10.rb +2 -2
- data/example/ex11.rb +5 -5
- data/example/ex12.rb +6 -6
- data/example/ex13.rb +4 -4
- data/example/ex14.rb +4 -4
- data/example/ex15.rb +2 -2
- data/example/ex16.rb +8 -8
- data/example/ex17.rb +12 -11
- data/example/ex18.rb +5 -5
- data/example/ex19.rb +3 -3
- data/example/ex20.rb +3 -3
- data/example/ex21.rb +3 -3
- data/example/ex22.rb +1 -1
- data/example/ex23.rb +2 -2
- data/example/ex24.rb +4 -4
- data/example/ex25.rb +41 -0
- data/example/example_helper.rb +38 -3
- data/example/sample_service.rb +4 -4
- data/hack_night/exercise/prob-3.rb +3 -3
- data/hack_night/exercise/prob-6.rb +2 -2
- data/hack_night/exercise/prob-7.rb +2 -2
- data/hack_night/solution/prob-2.rb +2 -2
- data/hack_night/solution/prob-3.rb +3 -3
- data/hack_night/solution/prob-6.rb +7 -6
- data/hack_night/solution/prob-7.rb +6 -6
- data/{spec → lab}/const_get_speed_spec.rb +0 -0
- data/lib/asir.rb +29 -7
- data/lib/asir/additional_data.rb +25 -0
- data/lib/asir/channel.rb +4 -5
- data/lib/asir/client.rb +29 -13
- data/lib/asir/config.rb +8 -0
- data/lib/asir/description.rb +34 -0
- data/lib/asir/environment.rb +96 -0
- data/lib/asir/error.rb +4 -1
- data/lib/asir/invoker.rb +14 -0
- data/lib/asir/main.rb +84 -103
- data/lib/asir/message.rb +1 -1
- data/lib/asir/poll_throttle.rb +53 -0
- data/lib/asir/retry_behavior.rb +1 -1
- data/lib/asir/thread_variable.rb +183 -0
- data/lib/asir/transport.rb +36 -23
- data/lib/asir/transport/beanstalk.rb +18 -52
- data/lib/asir/transport/conduit.rb +42 -0
- data/lib/asir/transport/connection_oriented.rb +32 -56
- data/lib/asir/transport/delegation.rb +5 -5
- data/lib/asir/transport/demux.rb +33 -0
- data/lib/asir/transport/file.rb +5 -3
- data/lib/asir/transport/payload_io.rb +8 -4
- data/lib/asir/transport/resque.rb +212 -0
- data/lib/asir/transport/stream.rb +19 -9
- data/lib/asir/transport/tcp_socket.rb +3 -2
- data/lib/asir/transport/zmq.rb +14 -17
- data/lib/asir/uri_config.rb +51 -0
- data/lib/asir/version.rb +1 -1
- data/spec/client_spec.rb +48 -0
- data/spec/demux_spec.rb +38 -0
- data/spec/json_spec.rb +0 -2
- data/spec/message_spec.rb +68 -0
- data/spec/performance_spec.rb +66 -0
- data/spec/spec_helper.rb +34 -0
- data/spec/thread_variable_spec.rb +135 -0
- data/spec/transport_spec.rb +82 -0
- metadata +28 -4
data/Gemfile
CHANGED
data/README.textile
CHANGED
@@ -28,10 +28,11 @@ h3. Features
|
|
28
28
|
** HTTP under WEBrick or as Rack application.
|
29
29
|
** Beanstalkd.
|
30
30
|
** ZeroMQ.
|
31
|
+
** Resque.
|
31
32
|
** Buffered transports.
|
32
33
|
** Broadcast transports.
|
33
34
|
** Fallback transports.
|
34
|
-
** Time-decaying retry logic.
|
35
|
+
** Time-decaying retry and polling logic.
|
35
36
|
* Support for multiple encodings:
|
36
37
|
** Marshal.
|
37
38
|
** XML.
|
@@ -42,7 +43,8 @@ h3. Features
|
|
42
43
|
** Chained encodings.
|
43
44
|
** Signed payloads.
|
44
45
|
|
45
|
-
h2. Platform support
|
46
|
+
h2. Platform support
|
47
|
+
|
46
48
|
* CRuby 1.8.7
|
47
49
|
* CRuby 1.9.3-head
|
48
50
|
* CRuby 2.0-head
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
1.0.1
|
data/asir.gemspec
CHANGED
@@ -1,11 +1,8 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
1
|
# -*- encoding: utf-8 -*-
|
5
2
|
|
6
3
|
Gem::Specification.new do |s|
|
7
4
|
s.name = %q{asir}
|
8
|
-
s.version = "0.
|
5
|
+
s.version = "1.0.1"
|
9
6
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
10
7
|
s.authors = ["Kurt Stephens"]
|
11
8
|
s.date = %q{2012-04-03}
|
data/asir.riterate.yml
CHANGED
data/bin/asir
CHANGED
data/example/asir_control.sh
CHANGED
@@ -4,21 +4,83 @@ dir="$(cd "$(dirname $0)" && /bin/pwd)"
|
|
4
4
|
PATH="$dir/../bin:$PATH"
|
5
5
|
export RUBYLIB="$dir/../example:$dir/../lib"
|
6
6
|
asir="asir verbose=9 config_rb=$dir/config/asir_config.rb"
|
7
|
-
|
7
|
+
args="$*"
|
8
|
+
args="${args:-ALL}"
|
8
9
|
# set -e
|
10
|
+
|
11
|
+
#############################
|
12
|
+
|
13
|
+
case "$args"
|
14
|
+
in
|
15
|
+
*webrick*|*ALL*)
|
16
|
+
|
9
17
|
$asir start webrick worker
|
10
18
|
sleep 1
|
19
|
+
$asir pid webrick worker
|
20
|
+
if $asir alive webrick worker; then
|
21
|
+
echo "alive webrick worker"
|
22
|
+
fi
|
11
23
|
|
12
24
|
ruby "$dir/asir_control_client_http.rb"
|
13
25
|
sleep 1
|
14
26
|
|
15
27
|
$asir stop webrick worker
|
16
28
|
sleep 1
|
29
|
+
$asir pid webrick worker
|
30
|
+
|
31
|
+
;;
|
32
|
+
esac
|
33
|
+
|
34
|
+
#############################
|
35
|
+
|
36
|
+
case "$args"
|
37
|
+
in
|
38
|
+
*zmq*|*ALL*)
|
17
39
|
|
18
40
|
$asir start zmq worker
|
19
41
|
sleep 1
|
42
|
+
$asir pid zmq worker
|
43
|
+
if $asir alive zmq worker; then
|
44
|
+
echo "alive"
|
45
|
+
fi
|
20
46
|
|
21
47
|
ruby "$dir/asir_control_client_zmq.rb"
|
22
48
|
sleep 1
|
23
49
|
|
50
|
+
$asir stop zmq worker
|
51
|
+
sleep 1
|
52
|
+
$asir pid zmq worker
|
53
|
+
|
54
|
+
;;
|
55
|
+
esac
|
56
|
+
|
57
|
+
#############################
|
58
|
+
|
59
|
+
case "$args"
|
60
|
+
in
|
61
|
+
*resque*|*ALL*)
|
62
|
+
|
63
|
+
$asir start resque conduit
|
64
|
+
sleep 1
|
65
|
+
if $asir alive resque conduit; then
|
66
|
+
echo "resque conduit alive"
|
67
|
+
fi
|
68
|
+
$asir start resque worker
|
69
|
+
sleep 1
|
70
|
+
$asir pid resque worker
|
71
|
+
if $asir alive resque worker; then
|
72
|
+
echo "resque worker alive"
|
73
|
+
fi
|
74
|
+
|
75
|
+
ruby "$dir/asir_control_client_resque.rb"
|
76
|
+
sleep 1
|
77
|
+
$asir stop resque worker
|
78
|
+
sleep 1
|
79
|
+
$asir stop resque conduit
|
80
|
+
|
81
|
+
;;
|
82
|
+
esac
|
83
|
+
|
84
|
+
#############################
|
85
|
+
|
24
86
|
exit 0
|
@@ -2,10 +2,10 @@ require 'example_helper'
|
|
2
2
|
require 'asir/transport/http'
|
3
3
|
require 'asir/coder/marshal'
|
4
4
|
begin
|
5
|
-
Email.
|
5
|
+
Email.asir.transport = t =
|
6
6
|
ASIR::Transport::HTTP.new(:uri => "http://localhost:30000/asir")
|
7
7
|
t.encoder = ASIR::Coder::Marshal.new
|
8
|
-
pr Email.
|
8
|
+
pr Email.asir.send_email(:pdf_invoice,
|
9
9
|
:to => "user@email.com",
|
10
10
|
:customer => @customer)
|
11
11
|
ensure
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'example_helper'
|
2
|
+
gem 'resque'
|
3
|
+
require 'asir/transport/resque'
|
4
|
+
require 'asir/coder/marshal'
|
5
|
+
begin
|
6
|
+
Email.asir.transport = t =
|
7
|
+
ASIR::Transport::Resque.new
|
8
|
+
t.one_way = true
|
9
|
+
t.encoder = ASIR::Coder::Marshal.new
|
10
|
+
pr Email.asir.send_email(:pdf_invoice,
|
11
|
+
:to => "user@email.com",
|
12
|
+
:customer => @customer)
|
13
|
+
ensure
|
14
|
+
t.close rescue nil
|
15
|
+
end
|
16
|
+
|
@@ -2,11 +2,11 @@ require 'example_helper'
|
|
2
2
|
require 'asir/transport/zmq'
|
3
3
|
require 'asir/coder/marshal'
|
4
4
|
begin
|
5
|
-
Email.
|
6
|
-
ASIR::Transport::Zmq.new
|
5
|
+
Email.asir.transport = t =
|
6
|
+
ASIR::Transport::Zmq.new(:uri => "tcp://localhost:31000") # "/asir"
|
7
7
|
t.one_way = true
|
8
8
|
t.encoder = ASIR::Coder::Marshal.new
|
9
|
-
pr Email.
|
9
|
+
pr Email.asir.send_email(:pdf_invoice,
|
10
10
|
:to => "user@email.com",
|
11
11
|
:customer => @customer)
|
12
12
|
ensure
|
@@ -1,13 +1,15 @@
|
|
1
1
|
# Used by asir/bin/asir.
|
2
2
|
# Configures asir worker transport and error logging.
|
3
|
-
# asir object is bound to ASIR::
|
3
|
+
# asir object is bound to ASIR::Environment instance.
|
4
4
|
|
5
|
-
$stderr.puts "asir.
|
6
|
-
case asir.
|
7
|
-
when :
|
5
|
+
$stderr.puts "asir.phase = #{asir.phase.inspect}" if asir.verbose >= 1
|
6
|
+
case asir.phase
|
7
|
+
when :configure
|
8
8
|
# NOTHING
|
9
9
|
true
|
10
10
|
when :environment
|
11
|
+
require 'rubygems'
|
12
|
+
|
11
13
|
require 'asir'
|
12
14
|
require 'asir/transport/file'
|
13
15
|
require 'asir/coder/marshal'
|
@@ -17,6 +19,9 @@ when :environment
|
|
17
19
|
require 'example_helper'
|
18
20
|
require 'sample_service'
|
19
21
|
require 'unsafe_service'
|
22
|
+
when :start
|
23
|
+
# NOTHING
|
24
|
+
true
|
20
25
|
when :transport
|
21
26
|
# Compose with Marshal for final coding.
|
22
27
|
coder = ASIR::Coder::Marshal.new
|
@@ -32,18 +37,25 @@ when :transport
|
|
32
37
|
# Setup requested Transport.
|
33
38
|
case asir.adjective
|
34
39
|
when :beanstalk
|
40
|
+
require 'asir/transport/beanstalk'
|
35
41
|
transport = ASIR::Transport::Beanstalk.new
|
36
|
-
transport[:worker_processes] = 3
|
37
42
|
when :http, :webrick
|
43
|
+
require 'asir/transport/webrick'
|
38
44
|
transport = ASIR::Transport::Webrick.new
|
39
45
|
transport.uri = "http://localhost:#{30000 + asir.identifier.to_s.to_i}/asir"
|
40
46
|
when :rack
|
47
|
+
require 'asir/transport/rack'
|
41
48
|
transport = ASIR::Transport::Rack.new
|
42
49
|
transport.uri = "http://localhost:#{30000 + asir.identifier.to_s.to_i}/asir"
|
43
50
|
when :zmq
|
51
|
+
reqiore 'asir/transport/zmq'
|
44
52
|
transport = ASIR::Transport::Zmq.new
|
45
53
|
transport.one_way = true
|
46
54
|
transport.uri = "tcp://localhost:#{31000 + asir.identifier.to_s.to_i}" # /asir"
|
55
|
+
when :resque
|
56
|
+
gem 'resque'
|
57
|
+
require 'asir/transport/resque'
|
58
|
+
transport = ASIR::Transport::Resque.new
|
47
59
|
else
|
48
60
|
raise "Cannot configure Transport for #{asir.adjective}"
|
49
61
|
end
|
@@ -51,13 +63,13 @@ when :transport
|
|
51
63
|
transport.encoder = coder
|
52
64
|
transport._logger = STDERR
|
53
65
|
transport._log_enabled = true
|
54
|
-
transport.verbose = 3
|
66
|
+
# transport.verbose = 3
|
55
67
|
transport.on_exception =
|
56
|
-
lambda { | transport, exc, phase, message,
|
68
|
+
lambda { | transport, exc, phase, message, result |
|
57
69
|
error_transport.send_request(message)
|
58
70
|
}
|
59
71
|
|
60
72
|
transport
|
61
73
|
else
|
62
|
-
$stderr.puts "Warning: unhandled asir.
|
74
|
+
$stderr.puts "Warning: unhandled asir.phase: #{asir.phase.inspect}"
|
63
75
|
end
|
data/example/ex02.rb
CHANGED
data/example/ex03.rb
CHANGED
@@ -4,10 +4,10 @@
|
|
4
4
|
|
5
5
|
require 'example_helper'
|
6
6
|
begin
|
7
|
-
Email.
|
7
|
+
Email.asir.transport = t =
|
8
8
|
ASIR::Transport::Subprocess.new
|
9
9
|
|
10
|
-
pr Email.
|
10
|
+
pr Email.asir.send_email(:pdf_invoice,
|
11
11
|
:to => "user@email.com",
|
12
12
|
:customer => @customer)
|
13
13
|
end
|
data/example/ex04.rb
CHANGED
@@ -4,11 +4,11 @@
|
|
4
4
|
require 'example_helper'
|
5
5
|
begin
|
6
6
|
File.unlink(service_log = "#{__FILE__}.service.log") rescue nil
|
7
|
-
Email.
|
7
|
+
Email.asir.transport = t =
|
8
8
|
ASIR::Transport::File.new(:file => service_log)
|
9
9
|
t.encoder =
|
10
10
|
ASIR::Coder::Yaml.new
|
11
|
-
pr Email.
|
11
|
+
pr Email.asir.send_email(:pdf_invoice,
|
12
12
|
:to => "user@email.com",
|
13
13
|
:customer => @customer)
|
14
14
|
ensure
|
data/example/ex05.rb
CHANGED
data/example/ex06.rb
CHANGED
@@ -1,19 +1,20 @@
|
|
1
1
|
# !SLIDE :capture_code_output true
|
2
2
|
# One-way, named pipe service
|
3
3
|
|
4
|
+
$stderr.puts " #{$$} at #{__FILE__}:#{__LINE__}"
|
5
|
+
|
4
6
|
require 'example_helper'
|
5
7
|
begin
|
6
8
|
File.unlink(service_pipe = "service.pipe") rescue nil
|
7
|
-
Email.
|
9
|
+
Email.asir.transport = t =
|
8
10
|
ASIR::Transport::File.new(:file => service_pipe)
|
9
11
|
t.encoder =
|
10
12
|
ASIR::Coder::Yaml.new
|
11
|
-
t.prepare_pipe_server!
|
12
13
|
server_process do
|
13
|
-
t.
|
14
|
+
t.prepare_server!
|
15
|
+
t.run_server!
|
14
16
|
end
|
15
|
-
|
16
|
-
pr Email.client.send_email(:pdf_invoice, :to => "user@email.com", :customer => @customer)
|
17
|
+
pr Email.asir.send_email(:pdf_invoice, :to => "user@email.com", :customer => @customer)
|
17
18
|
ensure
|
18
19
|
t.close; sleep 1; server_kill
|
19
20
|
end
|
data/example/ex07.rb
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
require 'example_helper'
|
5
5
|
begin
|
6
6
|
File.unlink(service_pipe = "service.pipe") rescue nil
|
7
|
-
Email.
|
7
|
+
Email.asir.transport = t =
|
8
8
|
ASIR::Transport::File.new(:file => service_pipe)
|
9
9
|
t.encoder =
|
10
10
|
ASIR::Coder::Chain.new(:encoders =>
|
@@ -16,7 +16,7 @@ begin
|
|
16
16
|
server_process do
|
17
17
|
t.run_pipe_server!
|
18
18
|
end
|
19
|
-
pr Email.
|
19
|
+
pr Email.asir.send_email(:pdf_invoice, :to => "user@email.com", :customer => @customer)
|
20
20
|
ensure
|
21
21
|
t.close; sleep 1; server_kill
|
22
22
|
end
|
data/example/ex08.rb
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
require 'example_helper'
|
5
5
|
begin
|
6
6
|
File.unlink(service_pipe = "service.pipe") rescue nil
|
7
|
-
Email.
|
7
|
+
Email.asir.transport = t =
|
8
8
|
ASIR::Transport::File.new(:file => service_pipe)
|
9
9
|
t.encoder =
|
10
10
|
ASIR::Coder::Chain.new(:encoders =>
|
@@ -17,7 +17,7 @@ begin
|
|
17
17
|
t.run_pipe_server!
|
18
18
|
end
|
19
19
|
s.secret = 'I do not know the secret! :('
|
20
|
-
pr Email.
|
20
|
+
pr Email.asir.send_email(:pdf_invoice, :to => "user@email.com", :customer => @customer)
|
21
21
|
ensure
|
22
22
|
t.close; sleep 1; server_kill
|
23
23
|
end
|
data/example/ex09.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
|
4
4
|
require 'example_helper'
|
5
5
|
begin
|
6
|
-
Email.
|
6
|
+
Email.asir.transport = t =
|
7
7
|
ASIR::Transport::TcpSocket.new(:port => 30909)
|
8
8
|
t.encoder =
|
9
9
|
ASIR::Coder::Marshal.new
|
@@ -11,7 +11,7 @@ begin
|
|
11
11
|
server_process do
|
12
12
|
t.run_server!
|
13
13
|
end
|
14
|
-
pr Email.
|
14
|
+
pr Email.asir.send_email(:pdf_invoice,
|
15
15
|
:to => "user@email.com", :customer => @customer)
|
16
16
|
ensure
|
17
17
|
t.close; sleep 1; server_kill
|
data/example/ex10.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
|
4
4
|
require 'example_helper'
|
5
5
|
begin
|
6
|
-
Email.
|
6
|
+
Email.asir.transport = t =
|
7
7
|
ASIR::Transport::TcpSocket.new(:port => 30910)
|
8
8
|
t.encoder =
|
9
9
|
ASIR::Coder::Marshal.new
|
@@ -11,7 +11,7 @@ begin
|
|
11
11
|
server_process do
|
12
12
|
t.run_server!
|
13
13
|
end
|
14
|
-
pr Email.
|
14
|
+
pr Email.asir.do_raise("Raise Me!")
|
15
15
|
rescue Exception => err
|
16
16
|
pr [ :exception, err ]
|
17
17
|
ensure
|
data/example/ex11.rb
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
require 'example_helper'
|
5
5
|
begin
|
6
6
|
File.unlink(service_log = "#{__FILE__}.service.log") rescue nil
|
7
|
-
Email.
|
7
|
+
Email.asir.transport = t =
|
8
8
|
ASIR::Transport::Fallback.new(:transports => [
|
9
9
|
tcp = ASIR::Transport::TcpSocket.new(:port => 31911,
|
10
10
|
:encoder => ASIR::Coder::Marshal.new),
|
@@ -14,13 +14,13 @@ begin
|
|
14
14
|
ASIR::Transport::Subprocess.new,
|
15
15
|
]),
|
16
16
|
])
|
17
|
-
pr Email.
|
17
|
+
pr Email.asir.send_email(:pdf_invoice,
|
18
18
|
:to => "user@email.com", :customer => @customer)
|
19
19
|
server_process do
|
20
20
|
tcp.prepare_server!
|
21
21
|
tcp.run_server!
|
22
|
-
end
|
23
|
-
pr Email.
|
22
|
+
end
|
23
|
+
pr Email.asir.send_email(:pdf_invoice,
|
24
24
|
:to => "user2@email.com", :customer => @customer)
|
25
25
|
ensure
|
26
26
|
file.close rescue nil;
|
@@ -38,7 +38,7 @@ end
|
|
38
38
|
# EXPECT: service.log" contents:
|
39
39
|
# EXPECT: --- !ruby/object:ASIR::Message
|
40
40
|
# EXPECT: :transport_exceptions:
|
41
|
-
# EXPECT:
|
41
|
+
# EXPECT: Cannot connect to ASIR::Transport::TcpSocket tcp://127.0.0.1:
|
42
42
|
# EXPECT: arguments:
|
43
43
|
# EXPECT: - :pdf_invoice
|
44
44
|
# EXPECT/: :to: user@email.com
|