asir 1.0.5 → 1.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color -f d
data/ChangeLog ADDED
@@ -0,0 +1,9 @@
1
+ 2012-11-27 Kurt A. Stephens <ks.github@kurtstephens.com>
2
+
3
+ * v1.0.6: New version.
4
+ * lib/asir/transport/resque.rb: Fixed Resque::Worker initialization.
5
+ * lib/asir/transport/resque.rb: Support for redis-server 2.6 command line options.
6
+ * Changelog: Added Changelog
7
+ * asir.gemspec: Fixed Bundle and gemspec dependencies.
8
+ * Rakefile: Added rake prereq.
9
+
data/Gemfile CHANGED
@@ -1,15 +1,6 @@
1
1
  # -*- ruby -*-
2
2
  source "http://rubygems.org"
3
- gem 'uuid', '~> 2.3.5'
4
- # gem 'json', '~> 1.6.5' # Fails to load under jruby 1.6.6
5
- gem 'libxml-ruby', '~> 2.2.2'
6
- gem 'httpclient', '~> 2.2.4'
7
- gem 'zmq', '~> 2.1.4'
8
3
 
9
- group :development do
10
- gem "bundler", ">= 1.0.0"
11
- gem "rspec", "~> 2.0"
12
-
13
- require File.expand_path('../spec/debug_helper', __FILE__)
14
- end
4
+ # Specify your gem's dependencies in asir.gemspec
5
+ gemspec
15
6
 
data/README.textile CHANGED
@@ -50,3 +50,9 @@ h2. Platform support
50
50
  * CRuby 2.0-head
51
51
  * JRuby 1.6.x (with JRUBY_OPTS=--1.9) IN-PROGRESS
52
52
 
53
+ h2. Dependencies
54
+
55
+ * gem install zmq
56
+ ** zmq 2.1.4 needs a zmq 2.x library.
57
+ ** On OS X Macports: sudo port install zmq22.
58
+
data/Rakefile CHANGED
@@ -49,6 +49,19 @@ task :irb do
49
49
  sh "irb -Ilib -rasir"
50
50
  end
51
51
 
52
+ ######################################################################
53
+
54
+ desc "Install system prerequites"
55
+ task :prereq do
56
+ case RUBY_PLATFORM
57
+ when /darwin/i
58
+ sh "sudo port install zmq22"
59
+ when /linux/i
60
+ sh "sudo apt-get install libzmq-dev"
61
+ end
62
+ end
63
+
64
+ ######################################################################
52
65
  desc "Create slides."
53
66
  task :slides =>
54
67
  [
data/asir.gemspec CHANGED
@@ -1,44 +1,48 @@
1
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/version'
2
6
 
3
7
  Gem::Specification.new do |s|
8
+ gem = s
4
9
  s.name = %q{asir}
5
- s.version = "1.0.5"
6
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
10
+ s.version = ASIR::VERSION
7
11
  s.authors = ["Kurt Stephens"]
8
- s.date = %q{2012-11-26}
9
- s.description = %q{Abstracting Services in Ruby}
10
12
  s.email = %q{ks.ruby@kurtstephens.com}
11
- s.extra_rdoc_files = [
12
- "README.textile"
13
- ]
14
- s.files = `git ls-files`.split("\n")
15
- s.executables.push(*`git ls-files bin`.split("\n").map{|f| f.gsub('bin/', '')})
13
+ s.description = %q{Abstracting Services in Ruby}
14
+ s.summary = %q{Abstracting Services in Ruby}
16
15
  s.homepage = %q{http://github.com/kstephens/abstracting_services_in_ruby}
17
- s.rdoc_options = ["--charset=UTF-8"]
16
+
17
+ s.files = `git ls-files`.split($/)
18
+ s.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
19
+ s.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
20
  s.require_paths = ["lib"]
19
- s.rubygems_version = %q{1.3.7}
20
- s.summary = %q{Abstracting Services in Ruby}
21
- s.test_files = `git ls-files spec`.split("\n")
22
21
 
23
- s.add_dependency "uuid", "~> 2.3.5"
22
+ s.extra_rdoc_files = [ "README.textile" ]
23
+ s.rdoc_options = ["--charset=UTF-8"]
24
+
25
+ if RUBY_PLATFORM !~ /linux/i
26
+ # see lib/asir/uuid.rb
27
+ gem.add_dependency "uuid", "~> 2.3.6"
28
+ end
24
29
  s.add_dependency "redis", "~> 3.0.2"
25
30
  s.add_dependency "resque", "~> 1.23.0"
26
31
  s.add_dependency "httpclient", "~> 2.3.0"
27
32
  s.add_dependency "libxml-ruby", "~> 2.3.3"
28
33
  s.add_dependency "rack", "~> 1.4.1"
29
34
  s.add_dependency "zmq", "~> 2.1.4"
35
+ s.add_dependency "json", ">= 1.5.3"
30
36
 
37
+ s.add_development_dependency 'rake', '>= 0.9.0'
31
38
  s.add_development_dependency 'rspec', '~> 2.12.0'
32
- # s.add_development_dependency 'simplecov',
33
-
34
- if s.respond_to? :specification_version then
35
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
36
- s.specification_version = 3
37
-
38
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
39
- else
40
- end
39
+ s.add_development_dependency 'simplecov', '>= 0.1'
40
+ case RUBY_VERSION
41
+ when /^1\.8/
42
+ gem.add_development_dependency 'ruby-debug', '>= 0.1'
41
43
  else
44
+ gem.add_development_dependency 'ruby-debug19', '>= 0.1'
42
45
  end
46
+ # s.add_development_dependency 'simplecov',
43
47
  end
44
48
 
@@ -105,7 +105,7 @@ module ASIR
105
105
  save = Thread.current[:asir_transport_resque_instance]
106
106
  Thread.current[:asir_transport_resque_instance] = self
107
107
  poll_throttle throttle do
108
- $stderr.puts " #{$$} #{self} serve_stream_message!: resque_worker = #{resque_worker} on queues #{resque_worker.queues}" if @verbose >= 3
108
+ $stderr.puts " #{$$} #{self} serve_stream_message!: resque_worker = #{resque_worker} on queues #{resque_worker.queues.inspect}" if @verbose >= 3
109
109
  if job = resque_worker.reserve
110
110
  $stderr.puts " #{$$} #{self} serve_stream_message! job=#{job.class}:#{job.inspect}" if @verbose >= 2
111
111
  resque_worker.process(job)
@@ -167,7 +167,7 @@ module ASIR
167
167
  end
168
168
 
169
169
  def resque_worker
170
- @resque_worker ||= ::Resque::Worker.new(queues_)
170
+ @resque_worker ||= ::Resque::Worker.new(*queues_)
171
171
  end
172
172
 
173
173
  def server_on_start!
@@ -195,17 +195,45 @@ module ASIR
195
195
 
196
196
  #########################################
197
197
 
198
+ @@redis_server_version = nil
199
+ def redis_server_version
200
+ @@redis_server_version ||=
201
+ begin
202
+ case v = `redis-server --version`
203
+ when /v=([.0-9]+)/ # 3.x
204
+ v = $1
205
+ when / version ([.0-9]+)/ # 2.x
206
+ v = $1
207
+ else
208
+ v = 'UNKNOWN'
209
+ end
210
+ v
211
+ end
212
+ end
213
+
198
214
  def _start_conduit!
199
215
  @redis_dir ||= "/tmp"
200
216
  @redis_conf ||= "#{@redis_dir}/asir-redis-#{port}.conf"
201
217
  @redis_log ||= "#{@redis_dir}/asir-redis-#{port}.log"
202
- ::File.open(@redis_conf, "w+") do | out |
203
- out.puts "daemonize no"
204
- out.puts "port #{port}"
205
- out.puts "loglevel warning"
206
- out.puts "logfile #{@redis_log}"
218
+ @redis_cmd = [ 'redis-server' ]
219
+ case redis_server_version
220
+ when /^2\.4/
221
+ ::File.open(@redis_conf, "w+") do | out |
222
+ out.puts "daemonize no"
223
+ out.puts "port #{port}"
224
+ out.puts "loglevel warning"
225
+ out.puts "logfile #{@redis_log}"
226
+ end
227
+ @redis_cmd << @redis_conf
228
+ else
229
+ @redis_cmd <<
230
+ '--port' << port <<
231
+ '--loglevel' << 'warning' <<
232
+ '--logfile' << @redis_log
207
233
  end
208
- exec "redis-server", @redis_conf
234
+ @redis_cmd.map! { | x | x.to_s }
235
+ # $stderr.puts " redis_cmd = #{@redis_cmd * ' '}" if @verbose >= 1
236
+ exec *@redis_cmd
209
237
  end
210
238
  end
211
239
  # !SLIDE END
data/lib/asir/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module ASIR
2
- VERSION = "1.0.5"
2
+ VERSION = "1.0.6"
3
3
  end
data/spec/resque_spec.rb CHANGED
@@ -4,8 +4,33 @@ gem 'resque'
4
4
  require 'asir'
5
5
  require 'asir/transport/resque'
6
6
  require 'asir/coder/marshal'
7
+ require 'timeout'
7
8
 
8
9
  describe "ASIR::Transport::Resque" do
10
+ it "should be able to start/stop redis" do
11
+ with_cleanup! do
12
+ create_transport!
13
+ pid = Process.fork do
14
+ # exec "false" # simulate failure to start.
15
+ transport._start_conduit!
16
+ end
17
+ sleep 1
18
+ Process.kill('TERM', pid)
19
+ sleep 1
20
+ wpid, status = nil, nil
21
+ Timeout.timeout(5) do
22
+ wpid, status = Process.waitpid2(pid, Process::WUNTRACED)
23
+ end
24
+ # puts status.inspect
25
+ wpid.should == pid
26
+ status.stopsig.should == nil
27
+ status.termsig.should == nil
28
+ status.exited?.should == true
29
+ status.exitstatus.should == 0
30
+ status.success?.should == true
31
+ end
32
+ end
33
+
9
34
  it "should process and stop! gracefully" do
10
35
  with_cleanup! do
11
36
  create_transport!
@@ -14,12 +39,15 @@ describe "ASIR::Transport::Resque" do
14
39
 
15
40
  message_count = 0
16
41
  transport.after_receive_message = lambda do | t, message |
17
- $stderr.write ">#{message_count += 1}" if verbose
42
+ message_count += 1
43
+ $stderr.write ">#{message_count}" if verbose
18
44
  if message_count >= 5
19
45
  t.stop!
20
46
  end
21
47
  end
22
- start_server!
48
+ Timeout.timeout(20) do
49
+ start_server!
50
+ end
23
51
 
24
52
  message_count.should == 5
25
53
  exceptions.should == [ ]
@@ -32,12 +60,15 @@ describe "ASIR::Transport::Resque" do
32
60
  message_count = 0
33
61
  lambda do
34
62
  transport.after_receive_message = lambda do | t, message |
35
- $stderr.write ">#{message_count += 1}" if verbose
63
+ message_count += 1
64
+ $stderr.write ">#{message_count}" if verbose
36
65
  if message_count >= 10
37
66
  t.stop!
38
67
  end
39
68
  end
40
- start_server!
69
+ Timeout.timeout(20) do
70
+ start_server!
71
+ end
41
72
  end.should raise_error(Redis::CannotConnectError)
42
73
  message_count.should == 0
43
74
  exceptions.should == [ ]
@@ -54,7 +85,8 @@ describe "ASIR::Transport::Resque" do
54
85
  message_count = 0
55
86
  lambda do
56
87
  transport.after_receive_message = lambda do | t, message |
57
- $stderr.write ">#{message_count += 1}" if verbose
88
+ message_count += 1
89
+ $stderr.write ">#{message_count}" if verbose
58
90
  if message_count >= 5
59
91
  stop_client!
60
92
  stop_conduit! :signal => 9
@@ -63,7 +95,9 @@ describe "ASIR::Transport::Resque" do
63
95
  t.stop!
64
96
  end
65
97
  end
66
- start_server!
98
+ Timeout.timeout(20) do
99
+ start_server!
100
+ end
67
101
  raise "start_server! exited"
68
102
  end.should raise_error(Redis::CannotConnectError)
69
103
  message_count.should == 5
@@ -76,7 +110,7 @@ describe "ASIR::Transport::Resque" do
76
110
  before :each do
77
111
  @target = ASIR::Test::ResqueTarget.new
78
112
  @exceptions = [ ]
79
- @verbose = true
113
+ @verbose = (ENV['ASIR_TEST_VERBOSE'] || 0).to_i > 0
80
114
  end
81
115
 
82
116
  def with_cleanup!
@@ -91,11 +125,13 @@ describe "ASIR::Transport::Resque" do
91
125
  @uri = "redis://localhost:23456"
92
126
  @transport = ASIR::Transport::Resque.new(:uri => @uri)
93
127
  transport.encoder = ASIR::Coder::Marshal.new
94
- transport._logger = $stderr
95
- transport._log_enabled = true
96
- ASIR::Client::Proxy.config_callbacks[target.class] = lambda { | proxy |
128
+ if verbose
129
+ transport._logger = $stderr
130
+ transport._log_enabled = true
131
+ end
132
+ ASIR::Client::Proxy.config_callbacks[target.class] = lambda do | proxy |
97
133
  proxy.transport = transport
98
- }
134
+ end
99
135
  end
100
136
 
101
137
  def start_conduit!
@@ -115,7 +151,8 @@ describe "ASIR::Transport::Resque" do
115
151
  # transport.verbose = 3
116
152
  i = 0
117
153
  loop do
118
- $stderr.write "<#{i += 1}" if verbose
154
+ i += 1
155
+ $stderr.write "<#{i}" if verbose
119
156
  target.asir.eval! "2 + 2"
120
157
  sleep 0.25
121
158
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asir
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-26 00:00:00.000000000 Z
12
+ date: 2012-11-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: uuid
@@ -18,7 +18,7 @@ dependencies:
18
18
  requirements:
19
19
  - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: 2.3.5
21
+ version: 2.3.6
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ~>
28
28
  - !ruby/object:Gem::Version
29
- version: 2.3.5
29
+ version: 2.3.6
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: redis
32
32
  requirement: !ruby/object:Gem::Requirement
@@ -123,6 +123,38 @@ dependencies:
123
123
  - - ~>
124
124
  - !ruby/object:Gem::Version
125
125
  version: 2.1.4
126
+ - !ruby/object:Gem::Dependency
127
+ name: json
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: 1.5.3
134
+ type: :runtime
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: 1.5.3
142
+ - !ruby/object:Gem::Dependency
143
+ name: rake
144
+ requirement: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ! '>='
148
+ - !ruby/object:Gem::Version
149
+ version: 0.9.0
150
+ type: :development
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ! '>='
156
+ - !ruby/object:Gem::Version
157
+ version: 0.9.0
126
158
  - !ruby/object:Gem::Dependency
127
159
  name: rspec
128
160
  requirement: !ruby/object:Gem::Requirement
@@ -139,6 +171,38 @@ dependencies:
139
171
  - - ~>
140
172
  - !ruby/object:Gem::Version
141
173
  version: 2.12.0
174
+ - !ruby/object:Gem::Dependency
175
+ name: simplecov
176
+ requirement: !ruby/object:Gem::Requirement
177
+ none: false
178
+ requirements:
179
+ - - ! '>='
180
+ - !ruby/object:Gem::Version
181
+ version: '0.1'
182
+ type: :development
183
+ prerelease: false
184
+ version_requirements: !ruby/object:Gem::Requirement
185
+ none: false
186
+ requirements:
187
+ - - ! '>='
188
+ - !ruby/object:Gem::Version
189
+ version: '0.1'
190
+ - !ruby/object:Gem::Dependency
191
+ name: ruby-debug19
192
+ requirement: !ruby/object:Gem::Requirement
193
+ none: false
194
+ requirements:
195
+ - - ! '>='
196
+ - !ruby/object:Gem::Version
197
+ version: '0.1'
198
+ type: :development
199
+ prerelease: false
200
+ version_requirements: !ruby/object:Gem::Requirement
201
+ none: false
202
+ requirements:
203
+ - - ! '>='
204
+ - !ruby/object:Gem::Version
205
+ version: '0.1'
142
206
  description: Abstracting Services in Ruby
143
207
  email: ks.ruby@kurtstephens.com
144
208
  executables:
@@ -148,6 +212,8 @@ extra_rdoc_files:
148
212
  - README.textile
149
213
  files:
150
214
  - .gitignore
215
+ - .rspec
216
+ - ChangeLog
151
217
  - Gemfile
152
218
  - README.textile
153
219
  - Rakefile