asir_beanstalk 1.1.1
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/.gitignore +18 -0
- data/.rspec +1 -0
- data/Changelog +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +34 -0
- data/asir_beanstalk.gemspec +26 -0
- data/example/ex01.rb +34 -0
- data/example/example_helper.rb +77 -0
- data/example/sample_service.rb +24 -0
- data/lib/asir/transport/beanstalk.rb +184 -0
- data/lib/asir_beanstalk.rb +8 -0
- data/lib/asir_beanstalk/version.rb +3 -0
- data/spec/example_spec.rb +88 -0
- data/spec/spec_helper.rb +37 -0
- metadata +133 -0
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color -f d
|
data/Changelog
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Kurt Stephens
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# asir_beanstalk
|
2
|
+
|
3
|
+
Beanstalk ASIR transport.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'asir_beanstalk'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install asir_beanstalk
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
See example/.
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
|
3
|
+
gem 'rspec'
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
|
6
|
+
desc "Run specs"
|
7
|
+
RSpec::Core::RakeTask.new(:spec) do |t|
|
8
|
+
t.pattern = "./spec/**/*_spec.rb" # don't need this, it's default.
|
9
|
+
# Put spec opts in a file named .rspec in root
|
10
|
+
end
|
11
|
+
|
12
|
+
desc "Generate code coverage"
|
13
|
+
RSpec::Core::RakeTask.new(:coverage) do |t|
|
14
|
+
t.pattern = "./spec/**/*_spec.rb" # don't need this, it's default.
|
15
|
+
t.rcov = true
|
16
|
+
t.rcov_opts = ['--exclude', 'spec']
|
17
|
+
end
|
18
|
+
|
19
|
+
######################################################################
|
20
|
+
|
21
|
+
desc "Default => :test"
|
22
|
+
task :default => :test
|
23
|
+
|
24
|
+
desc "Run all tests"
|
25
|
+
task :test => [ :spec ]
|
26
|
+
|
27
|
+
desc "Run examples."
|
28
|
+
task :example do
|
29
|
+
ENV["ASIR_EXAMPLE_SILENT"]="1"
|
30
|
+
Dir["example/ex[0-9]*.rb"].each do | rb |
|
31
|
+
sh %Q{ruby -I example -I lib #{rb}}
|
32
|
+
end
|
33
|
+
ENV.delete("ASIR_EXAMPLE_SILENT")
|
34
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
# -*- ruby -*-
|
3
|
+
lib = File.expand_path('../lib', __FILE__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'asir_beanstalk/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |gem|
|
8
|
+
gem.name = "asir_beanstalk"
|
9
|
+
gem.version = AsirBeanstalk::VERSION
|
10
|
+
gem.authors = ["Kurt Stephens"]
|
11
|
+
gem.email = ["ks.github@kurtstephens.com"]
|
12
|
+
gem.description = %q{Beanstalkd transport for ASIR}
|
13
|
+
gem.summary = %q{Beanstalkd transport for ASIR}
|
14
|
+
gem.homepage = "http://github.com/kstephens/abstracting_services_in_ruby"
|
15
|
+
|
16
|
+
gem.files = `git ls-files`.split($/)
|
17
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
18
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
19
|
+
gem.require_paths = ["lib"]
|
20
|
+
|
21
|
+
gem.add_dependency "asir", "~> 1.1.0"
|
22
|
+
|
23
|
+
gem.add_development_dependency 'rake', '>= 0.9.0'
|
24
|
+
gem.add_development_dependency 'rspec', '~> 2.12.0'
|
25
|
+
gem.add_development_dependency 'simplecov', '>= 0.1'
|
26
|
+
end
|
data/example/ex01.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# !SLIDE :capture_code_output true
|
2
|
+
# Asynchronous beanstalkd service
|
3
|
+
|
4
|
+
require 'example_helper'
|
5
|
+
require 'asir/transport/beanstalk'
|
6
|
+
require 'asir/coder/zlib'
|
7
|
+
begin
|
8
|
+
Email.asir.transport = t =
|
9
|
+
ASIR::Transport::Beanstalk.new(:address => '127.0.0.1', :port => 30904)
|
10
|
+
t.encoder =
|
11
|
+
ASIR::Coder::Chain.new(:encoders =>
|
12
|
+
[ ASIR::Coder::Marshal.new,
|
13
|
+
ASIR::Coder::Zlib.new, ])
|
14
|
+
t.start_conduit!; sleep 1
|
15
|
+
pr Email.asir.send_email(:pdf_invoice,
|
16
|
+
:to => "user@email.com", :customer => @customer)
|
17
|
+
sleep 2
|
18
|
+
server_process do
|
19
|
+
t.prepare_server!
|
20
|
+
t.run_server!
|
21
|
+
end
|
22
|
+
rescue Object => err
|
23
|
+
$stderr.puts "#{err.inspect}\n#{err.backtrace * "\n"}"
|
24
|
+
ensure
|
25
|
+
t.close; sleep 3; server_kill; sleep 2
|
26
|
+
t.stop_conduit!
|
27
|
+
end
|
28
|
+
|
29
|
+
# !SLIDE END
|
30
|
+
# EXPECT: : client process
|
31
|
+
# EXPECT: : server process
|
32
|
+
# EXPECT: : Email.send_mail :pdf_invoice
|
33
|
+
# EXPECT: : pr: nil
|
34
|
+
|
@@ -0,0 +1,77 @@
|
|
1
|
+
# Sample client support
|
2
|
+
#
|
3
|
+
require 'rubygems'
|
4
|
+
case RUBY_PLATFORM
|
5
|
+
when /java/i
|
6
|
+
gem 'spoon'; require 'spoon'
|
7
|
+
end
|
8
|
+
|
9
|
+
$: << File.expand_path("../../lib", __FILE__)
|
10
|
+
gem 'asir'
|
11
|
+
|
12
|
+
require 'asir'
|
13
|
+
require 'asir/coder/chain'
|
14
|
+
require 'asir/coder/marshal'
|
15
|
+
ASIR::Log.enabled = true unless ENV['ASIR_EXAMPLE_SILENT']
|
16
|
+
require 'sample_service'
|
17
|
+
|
18
|
+
require 'pp'
|
19
|
+
|
20
|
+
@customer = 123
|
21
|
+
|
22
|
+
class ::Object
|
23
|
+
|
24
|
+
def pr result
|
25
|
+
$stdout.puts "*** #{$$}: pr: #{PP.pp(result, '')}"
|
26
|
+
end
|
27
|
+
|
28
|
+
def server_process &blk
|
29
|
+
# $stderr.puts " at #{__FILE__}:#{__LINE__}"
|
30
|
+
case RUBY_PLATFORM
|
31
|
+
when /java/i
|
32
|
+
# JRuby cannot fork.
|
33
|
+
# So we must prevent spawn a new jruby and
|
34
|
+
# instruct it to only run the server blk, and not
|
35
|
+
# the subsequent client code.
|
36
|
+
# In other words, we cannot rely on how Process.fork
|
37
|
+
# terminates within the block.
|
38
|
+
if ENV['ASIR_JRUBY_SPAWNED']
|
39
|
+
$stderr.puts " spawned server at #{__FILE__}:#{__LINE__}"
|
40
|
+
puts "*** #{$$}: server process"; $stdout.flush
|
41
|
+
yield
|
42
|
+
Process.exit!(0)
|
43
|
+
# dont do client, client is our parent process.
|
44
|
+
else
|
45
|
+
$stderr.puts " spawning at #{__FILE__}:#{__LINE__}"
|
46
|
+
ENV['ASIR_JRUBY_SPAWNED'] = "1"
|
47
|
+
cmd = "ruby -I #{File.dirname(__FILE__)} -I #{File.expand_path('../../lib', __FILE__)} #{$0} #{ARGV * ' '}"
|
48
|
+
$stderr.puts " cmd = #{cmd}"
|
49
|
+
$server_pid = Spoon.spawnp(cmd)
|
50
|
+
ENV.delete('ASIR_JRUBY_SPAWNED')
|
51
|
+
$stderr.puts " spawned #{$server_pid} at #{__FILE__}:#{__LINE__}"
|
52
|
+
end
|
53
|
+
else
|
54
|
+
# $stderr.puts " at #{__FILE__}:#{__LINE__}"
|
55
|
+
$server_pid = Process.fork do
|
56
|
+
puts "*** #{$$}: server process"; $stdout.flush
|
57
|
+
yield
|
58
|
+
end
|
59
|
+
end
|
60
|
+
sleep 1 # wait for server to be ready.
|
61
|
+
return false # do client.
|
62
|
+
end
|
63
|
+
|
64
|
+
def server_kill
|
65
|
+
if $server_pid
|
66
|
+
Process.kill 9, $server_pid
|
67
|
+
Process.waitpid($server_pid)
|
68
|
+
end
|
69
|
+
rescue Errno::ESRCH
|
70
|
+
ensure
|
71
|
+
$server_pid = nil
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
puts "*** #{$$}: client process"; $stdout.flush
|
77
|
+
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'asir'
|
2
|
+
# Added .asir support.
|
3
|
+
module Email
|
4
|
+
include ASIR::Client # Email.asir
|
5
|
+
def send_email template_name, options
|
6
|
+
$stderr.puts "*** #{$$}: Email.send_mail #{template_name.inspect} #{options.inspect}"
|
7
|
+
:ok
|
8
|
+
end
|
9
|
+
def do_raise msg
|
10
|
+
raise msg
|
11
|
+
end
|
12
|
+
extend self
|
13
|
+
end
|
14
|
+
|
15
|
+
class MyClass
|
16
|
+
include ASIR::Client
|
17
|
+
def initialize x
|
18
|
+
@x = x
|
19
|
+
end
|
20
|
+
def method_missing sel, *args
|
21
|
+
@x.send(sel, *args)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
@@ -0,0 +1,184 @@
|
|
1
|
+
require 'asir/transport/tcp_socket'
|
2
|
+
|
3
|
+
module ASIR
|
4
|
+
class Transport
|
5
|
+
# !SLIDE
|
6
|
+
# Beanstalk Transport
|
7
|
+
class Beanstalk < TcpSocket
|
8
|
+
LINE_TERMINATOR = "\r\n".freeze
|
9
|
+
|
10
|
+
attr_accessor :tube, :priority, :delay, :ttr
|
11
|
+
|
12
|
+
def initialize *args
|
13
|
+
@port ||= 11300
|
14
|
+
@tube ||= 'asir'
|
15
|
+
@priority ||= 0
|
16
|
+
@delay ||= 0
|
17
|
+
@ttr ||= 600
|
18
|
+
super
|
19
|
+
end
|
20
|
+
|
21
|
+
# !SLIDE
|
22
|
+
# Sends the encoded Message payload String.
|
23
|
+
def _send_message message, message_payload
|
24
|
+
stream.with_stream! do | s |
|
25
|
+
begin
|
26
|
+
match =
|
27
|
+
_beanstalk(s,
|
28
|
+
"put #{message[:beanstalk_priority] || @priority} #{message[:beanstalk_delay] || @delay} #{message[:beanstalk_ttr] || @ttr} #{message_payload.size}\r\n",
|
29
|
+
/\AINSERTED (\d+)\r\n\Z/,
|
30
|
+
message_payload)
|
31
|
+
job_id = message[:beanstalk_job_id] = match[1].to_i
|
32
|
+
_log { "beanstalk_job_id = #{job_id.inspect}" } if @verbose >= 2
|
33
|
+
rescue ::Exception => exc
|
34
|
+
message[:beanstalk_error] = exc
|
35
|
+
close
|
36
|
+
raise exc
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
RESERVE = "reserve\r\n".freeze
|
42
|
+
|
43
|
+
# !SLIDE
|
44
|
+
# Receives the encoded Message payload String.
|
45
|
+
def _receive_message channel, additional_data
|
46
|
+
channel.with_stream! do | stream |
|
47
|
+
begin
|
48
|
+
match =
|
49
|
+
_beanstalk(stream,
|
50
|
+
RESERVE,
|
51
|
+
/\ARESERVED (\d+) (\d+)\r\n\Z/)
|
52
|
+
additional_data[:beanstalk_job_id] = match[1].to_i
|
53
|
+
additional_data[:beanstalk_message_size] =
|
54
|
+
size = match[2].to_i
|
55
|
+
message_payload = stream.read(size)
|
56
|
+
_read_line_and_expect! stream, /\A\r\n\Z/
|
57
|
+
# Pass the original stream used to #_send_result below.
|
58
|
+
[ message_payload, stream ]
|
59
|
+
rescue ::Exception => exc
|
60
|
+
_log { [ :_receive_message, :exception, exc ] }
|
61
|
+
additional_data[:beanstalk_error] = exc
|
62
|
+
channel.close
|
63
|
+
raise exc
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
# !SLIDE
|
69
|
+
# Sends the encoded Result payload String.
|
70
|
+
def _send_result message, result, result_payload, channel, stream
|
71
|
+
#
|
72
|
+
# There is a possibility here the following could happen:
|
73
|
+
#
|
74
|
+
# _receive_message
|
75
|
+
# channel == #<Channel:1>
|
76
|
+
# channel.stream == #<TCPSocket:1234>
|
77
|
+
# end
|
78
|
+
# ...
|
79
|
+
# ERROR OCCURES:
|
80
|
+
# channel.stream.close
|
81
|
+
# channel.stream = nil
|
82
|
+
# ...
|
83
|
+
# _send_result
|
84
|
+
# channel == #<Channel:1>
|
85
|
+
# channel.stream == #<TCPSocket:5678> # NEW CONNECTION
|
86
|
+
# stream.write "delete #{job_id}"
|
87
|
+
# ...
|
88
|
+
#
|
89
|
+
# Therefore: _receiver_message passes the original message stream to us.
|
90
|
+
# We insure that the same stream is still the active one and use it.
|
91
|
+
channel.with_stream! do | maybe_other_stream |
|
92
|
+
_log [ :_send_result, "stream lost" ] if maybe_other_stream != stream
|
93
|
+
job_id = message[:beanstalk_job_id] or raise "no beanstalk_job_id"
|
94
|
+
_beanstalk(stream,
|
95
|
+
"delete #{job_id}\r\n",
|
96
|
+
/\ADELETED\r\n\Z/)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
# !SLIDE
|
101
|
+
# Receives the encoded Result payload String.
|
102
|
+
def _receive_result message, opaque_result
|
103
|
+
nil
|
104
|
+
end
|
105
|
+
|
106
|
+
# !SLIDE
|
107
|
+
# Sets beanstalk_delay if message.delay was specified.
|
108
|
+
def relative_message_delay! message, now = nil
|
109
|
+
if delay = super
|
110
|
+
message[:beanstalk_delay] = delay.to_i
|
111
|
+
end
|
112
|
+
delay
|
113
|
+
end
|
114
|
+
|
115
|
+
# !SLIDE
|
116
|
+
# Beanstalk protocol support
|
117
|
+
|
118
|
+
# Send "something ...\r\n".
|
119
|
+
# Expect /\ASOMETHING (\d+)...\r\n".
|
120
|
+
def _beanstalk stream, message, expect, payload = nil
|
121
|
+
_log { [ :_beanstalk, :message, message ] } if @verbose >= 3
|
122
|
+
stream.write message
|
123
|
+
if payload
|
124
|
+
stream.write payload
|
125
|
+
stream.write LINE_TERMINATOR
|
126
|
+
end
|
127
|
+
stream.flush
|
128
|
+
if match = _read_line_and_expect!(stream, expect)
|
129
|
+
_log { [ :_beanstalk, :result, match[0] ] } if @verbose >= 3
|
130
|
+
end
|
131
|
+
match
|
132
|
+
end
|
133
|
+
|
134
|
+
def _after_connect! stream
|
135
|
+
if @tube
|
136
|
+
_beanstalk(stream,
|
137
|
+
"use #{@tube}\r\n",
|
138
|
+
/\AUSING #{@tube}\r\n\Z/)
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
# !SLIDE
|
143
|
+
# Beanstalk Server
|
144
|
+
def _server!
|
145
|
+
_log { "_server! #{uri}" } if @verbose >= 1
|
146
|
+
@server = connect!(:try_max => nil,
|
147
|
+
:try_sleep => 1,
|
148
|
+
:try_sleep_increment => 0.1,
|
149
|
+
:try_sleep_max => 10) do | stream |
|
150
|
+
if @tube
|
151
|
+
_beanstalk(stream,
|
152
|
+
"watch #{@tube}\r\n",
|
153
|
+
/\AWATCHING (\d+)\r\n\Z/)
|
154
|
+
end
|
155
|
+
end
|
156
|
+
self
|
157
|
+
end
|
158
|
+
|
159
|
+
def _server_accept_connection! server
|
160
|
+
prepare_server! unless @server
|
161
|
+
[ @server, @server ]
|
162
|
+
end
|
163
|
+
|
164
|
+
def _server_close_connection! in_stream, out_stream
|
165
|
+
# NOTHING
|
166
|
+
end
|
167
|
+
|
168
|
+
def stream_eof? stream
|
169
|
+
# Note: stream.eof? on a beanstalkd connection,
|
170
|
+
# will cause blocking read *forever* because
|
171
|
+
# beanstalk connections are long lived.
|
172
|
+
false
|
173
|
+
end
|
174
|
+
|
175
|
+
def _start_conduit!
|
176
|
+
addr = address ? "-l #{address} " : ""
|
177
|
+
cmd = "beanstalkd #{addr}-p #{port}"
|
178
|
+
exec(cmd)
|
179
|
+
end
|
180
|
+
end
|
181
|
+
# !SLIDE END
|
182
|
+
end # class
|
183
|
+
end # module
|
184
|
+
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require File.expand_path('../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
$:.unshift File.expand_path('../../example', __FILE__)
|
4
|
+
|
5
|
+
describe "ASIR Example" do
|
6
|
+
attr_accessor :file, :expects
|
7
|
+
|
8
|
+
before(:each) do
|
9
|
+
@expects = [ ]
|
10
|
+
end
|
11
|
+
|
12
|
+
after(:each) do
|
13
|
+
@file.should_not == nil
|
14
|
+
File.open(@file) do | fh |
|
15
|
+
until fh.eof?
|
16
|
+
line = fh.readline
|
17
|
+
line.chomp!
|
18
|
+
case
|
19
|
+
when line.sub!(/^\s*#\s*EXPECT\/:\s*/, '')
|
20
|
+
expect Regexp.new(line)
|
21
|
+
when line.sub!(/^\s*#\s*EXPECT!\/:\s*/, '')
|
22
|
+
expect Regexp.new(line), :'!~'
|
23
|
+
when line.sub!(/^\s*#\s*EXPECT:\s*/, '')
|
24
|
+
expect Regexp.new(Regexp.escape(line))
|
25
|
+
when line.sub!(/^\s*#\s*EXPECT!:\s*/, '')
|
26
|
+
expect Regexp.new(Regexp.escape(line)), :'!~'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
@output, @exit_code = run_file!(@file)
|
31
|
+
@exit_code.should == 0
|
32
|
+
@expects.empty?.should_not == true
|
33
|
+
@expects.each do | rx, mode |
|
34
|
+
$stderr.puts " Checking #{mode} #{rx.inspect}" if ENV['SPEC_VERBOSE']
|
35
|
+
case mode
|
36
|
+
when :'=~'
|
37
|
+
@output.should =~ rx
|
38
|
+
when :'!~'
|
39
|
+
@output.should_not =~ rx
|
40
|
+
else
|
41
|
+
raise ArgumentError
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def run_file! file, output = StringIO.new('')
|
47
|
+
progname_save, stdout_save, stderr_save = $0, $stdout, $stderr
|
48
|
+
exc = system_exit = nil; exit_code = 0
|
49
|
+
begin
|
50
|
+
if true
|
51
|
+
cmd = "ASIR_EXAMPLE_SILENT=1 ruby -I example -I lib #{file}"
|
52
|
+
$stderr.puts "\n Running #{cmd}:" if ENV['SPEC_VERBOSE']
|
53
|
+
output = `#{cmd} 2>&1 | tee #{file}.out`
|
54
|
+
else
|
55
|
+
$stderr.puts "\n Loading #{file}:" if ENV['SPEC_VERBOSE']
|
56
|
+
$stdout.puts "*** #{$$}: client process"; $stdout.flush
|
57
|
+
$stdout = $stderr = output
|
58
|
+
$0 = file
|
59
|
+
Kernel.load(file, true)
|
60
|
+
output = output.string if StringIO === output
|
61
|
+
end
|
62
|
+
rescue ::SystemExit => system_exit
|
63
|
+
exit_code = 1 # ???
|
64
|
+
rescue ::Exception => exc
|
65
|
+
exit_code = -1
|
66
|
+
end
|
67
|
+
[ output, exit_code ]
|
68
|
+
ensure
|
69
|
+
$0, $stdout, $stderr = progname_save, stdout_save, stderr_save
|
70
|
+
$stderr.write output if ENV['SPEC_VERBOSE']
|
71
|
+
if exc
|
72
|
+
stderr_save.puts "ERROR: #{file}: #{exc.inspect}\n#{exc.backtrace * "\n"}"
|
73
|
+
raise exc
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def expect rx, mode = :'=~'
|
78
|
+
@expects << [ rx, mode ]
|
79
|
+
end
|
80
|
+
|
81
|
+
Dir['example/**/ex[0-9]*.rb'].sort.each do | file |
|
82
|
+
title = File.open(file) { | fh | fh.read(4096) }
|
83
|
+
title = title =~ /#\s+!SLIDE[^\n]*\n\s*#\s*([^\n]+)/ && $1
|
84
|
+
it "#{file} - #{title}" do
|
85
|
+
@file = file
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
$:.unshift File.expand_path('../../lib', __FILE__)
|
3
|
+
|
4
|
+
gem 'asir'
|
5
|
+
require 'asir'
|
6
|
+
|
7
|
+
module ASIR
|
8
|
+
module Test
|
9
|
+
class TestError < ::Exception; end
|
10
|
+
class TestObject
|
11
|
+
include ASIR::Client
|
12
|
+
attr_accessor :spec, :arg, :cls, :msg, :transport, :message
|
13
|
+
def initialize spec
|
14
|
+
@spec = spec
|
15
|
+
end
|
16
|
+
|
17
|
+
def get_data!
|
18
|
+
@transport = ASIR::Transport.current
|
19
|
+
@message = @transport && @transport.message
|
20
|
+
end
|
21
|
+
|
22
|
+
def return_argument arg
|
23
|
+
get_data!
|
24
|
+
@arg = arg
|
25
|
+
arg
|
26
|
+
end
|
27
|
+
|
28
|
+
def raise_exception! cls, msg
|
29
|
+
get_data!
|
30
|
+
@cls = cls
|
31
|
+
@msg = msg
|
32
|
+
raise cls, msg
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
metadata
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: asir_beanstalk
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.1.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Kurt Stephens
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-12-04 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: asir
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.1.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 1.1.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 0.9.0
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 0.9.0
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rspec
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 2.12.0
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.12.0
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: simplecov
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0.1'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0.1'
|
78
|
+
description: Beanstalkd transport for ASIR
|
79
|
+
email:
|
80
|
+
- ks.github@kurtstephens.com
|
81
|
+
executables: []
|
82
|
+
extensions: []
|
83
|
+
extra_rdoc_files: []
|
84
|
+
files:
|
85
|
+
- .gitignore
|
86
|
+
- .rspec
|
87
|
+
- Changelog
|
88
|
+
- Gemfile
|
89
|
+
- LICENSE.txt
|
90
|
+
- README.md
|
91
|
+
- Rakefile
|
92
|
+
- asir_beanstalk.gemspec
|
93
|
+
- example/ex01.rb
|
94
|
+
- example/example_helper.rb
|
95
|
+
- example/sample_service.rb
|
96
|
+
- lib/asir/transport/beanstalk.rb
|
97
|
+
- lib/asir_beanstalk.rb
|
98
|
+
- lib/asir_beanstalk/version.rb
|
99
|
+
- spec/example_spec.rb
|
100
|
+
- spec/spec_helper.rb
|
101
|
+
homepage: http://github.com/kstephens/abstracting_services_in_ruby
|
102
|
+
licenses: []
|
103
|
+
post_install_message:
|
104
|
+
rdoc_options: []
|
105
|
+
require_paths:
|
106
|
+
- lib
|
107
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
108
|
+
none: false
|
109
|
+
requirements:
|
110
|
+
- - ! '>='
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
113
|
+
segments:
|
114
|
+
- 0
|
115
|
+
hash: -1937949383851329736
|
116
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
|
+
none: false
|
118
|
+
requirements:
|
119
|
+
- - ! '>='
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
segments:
|
123
|
+
- 0
|
124
|
+
hash: -1937949383851329736
|
125
|
+
requirements: []
|
126
|
+
rubyforge_project:
|
127
|
+
rubygems_version: 1.8.24
|
128
|
+
signing_key:
|
129
|
+
specification_version: 3
|
130
|
+
summary: Beanstalkd transport for ASIR
|
131
|
+
test_files:
|
132
|
+
- spec/example_spec.rb
|
133
|
+
- spec/spec_helper.rb
|