rrails 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/Changes.md CHANGED
@@ -1,8 +1,16 @@
1
- v0.2.0 2012-09-27 20:40:56 +0900
1
+ v0.3.0 2012-10-13 14:58:02 +0900
2
+ ------------------------------------------------------------------------
3
+ - FIX: some command that run under 0.1 sec is not output anything .
4
+ - FIX: kill child process(es) when client disconnects (thanks quark-zju)
5
+ - MOD: change reading handling from IO.select to read_nonblocking (thanks quark-zju)
6
+ - FIX: rescure EOFError when reading clisocks (thanks quark-zju)
7
+ - FIX: port number changable.
8
+
9
+ v0.2.0 2012-09-28 12:55:35 +0900
2
10
  ------------------------------------------------------------------------
3
- - Merge pull request #3 from kamipo/reloader thanks @kamipo
4
11
  - added reloader.
5
12
  - remove_connection is not necessary. included in establish_connection.
13
+ - wrote more doc.
6
14
 
7
15
  v0.1.0 2012-05-01 10:02:39 +0900
8
16
  ------------------------------------------------------------------------
data/Rakefile CHANGED
@@ -42,5 +42,6 @@ Rake::RDocTask.new do |rdoc|
42
42
  rdoc.rdoc_dir = 'rdoc'
43
43
  rdoc.title = "rrails #{version}"
44
44
  rdoc.rdoc_files.include('README*')
45
+ rdoc.rdoc_files.include('Changes.md')
45
46
  rdoc.rdoc_files.include('lib/**/*.rb')
46
47
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.3.0
data/lib/rrails/server.rb CHANGED
@@ -7,6 +7,7 @@ require 'shellwords'
7
7
 
8
8
  # FIXME: rails command require APP_PATH constants.
9
9
  APP_PATH = File.expand_path('./config/application')
10
+ PAGE_SIZE = 4096
10
11
 
11
12
  module RemoteRails
12
13
  # server to run rails/rake command.
@@ -21,7 +22,7 @@ module RemoteRails
21
22
  @app_path = File.expand_path('./config/application')
22
23
  # should not access to outside
23
24
  @host = 'localhost'
24
- @port = options[:poot] || DEFAULT_PORT[@rails_env]
25
+ @port = options[:port] || DEFAULT_PORT[@rails_env]
25
26
  @logger = Logger.new(options[:logfile] ? options[:logfile] : $stderr)
26
27
  end
27
28
 
@@ -45,17 +46,19 @@ module RemoteRails
45
46
  Thread.abort_on_exception = true
46
47
  loop do
47
48
  Thread.start(server.accept) do |s|
49
+ childpids = []
48
50
  begin
49
51
  while line = s.gets
50
52
  line.chomp!
51
53
  @logger.info("invoke: #{line}")
52
54
  start = Time.now
53
- self.dispatch(s, line)
55
+ self.dispatch(s, line) { |pid| childpids << pid }
54
56
  finish = Time.now
55
57
  s.puts("FINISHED\t#{ finish - start }")
56
58
  @logger.info("finished: #{line}")
57
59
  end
58
60
  rescue Errno::EPIPE => e
61
+ Process.kill 'TERM', *childpids unless childpids.empty?
59
62
  @logger.error("client disconnect: " + e.message)
60
63
  end
61
64
  end
@@ -76,8 +79,6 @@ module RemoteRails
76
79
  end
77
80
 
78
81
  def dispatch(sock, line)
79
- args = Shellwords.shellsplit(line)
80
- subcmd = args.shift
81
82
  servsock_out, clisock_out = UNIXSocket.pair
82
83
  servsock_err, clisock_err = UNIXSocket.pair
83
84
  pid = fork do
@@ -86,40 +87,44 @@ module RemoteRails
86
87
  ActiveRecord::Base.establish_connection if defined?(ActiveRecord::Base)
87
88
  STDOUT.reopen(servsock_out)
88
89
  STDERR.reopen(servsock_err)
89
- self.__send__("on_#{subcmd}", args)
90
+ execute *Shellwords.shellsplit(line)
90
91
  end
92
+ yield pid
91
93
  servsock_out.close
92
94
  servsock_err.close
95
+ buffers = {out: '', error: ''}
96
+ clisocks = {out: clisock_out, error: clisock_err}
93
97
  loop do
94
- if Process.waitpid(pid, Process::WNOHANG)
95
- return
96
- end
97
- if IO.select([clisock_out], [], [], 0.1)
98
- while line = clisock_out.gets
99
- line.chomp!
100
- sock.puts("OUT\t#{line}")
98
+ [:out, :error].each do |channel|
99
+ begin
100
+ buffers[channel] << clisocks[channel].read_nonblock(PAGE_SIZE)
101
+ while buffers[channel][/[\n\r]/]
102
+ line, buffers[channel] = buffers[channel].split(/[\n\r]/, 2)
103
+ sock.puts("#{channel.upcase}\t#{line}")
104
+ end
105
+ rescue Errno::EAGAIN, EOFError => ex
106
+ sleep 0.01
101
107
  end
102
108
  end
103
- if IO.select([clisock_err], [], [], 0.1)
104
- while line = clisock_err.gets
105
- line.chomp!
106
- @logger.error(line)
107
- sock.puts("ERROR\t#{line}")
108
- end
109
+ if Process.waitpid(pid, Process::WNOHANG)
110
+ return
109
111
  end
110
112
  end
111
113
  end
112
114
 
113
- def on_rails(args)
115
+ def execute(cmd, *args)
114
116
  ARGV.clear
115
117
  ARGV.concat(args)
116
- require 'rails/commands'
118
+ case cmd
119
+ when 'rails'
120
+ require 'rails/commands'
121
+ when 'rake'
122
+ ::Rake.application.run
123
+ else
124
+ @logger.warn "#{cmd} not supported"
125
+ raise RuntimeError.new("#{cmd} is not supported in rrails.")
126
+ end
117
127
  end
118
128
 
119
- def on_rake(args)
120
- ARGV.clear
121
- ARGV.concat(args)
122
- ::Rake.application.run
123
- end
124
129
  end
125
130
  end
data/rrails.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "rrails"
8
- s.version = "0.2.0"
8
+ s.version = "0.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Keiji, Yoshimi"]
12
- s.date = "2012-09-28"
12
+ s.date = "2012-10-13"
13
13
  s.description = "remote run rails/rake command"
14
14
  s.email = "walf443@gmail.com"
15
15
  s.executables = ["rrails", "rrails-server"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rrails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
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-09-28 00:00:00.000000000 Z
12
+ date: 2012-10-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: shoulda
@@ -132,7 +132,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
132
132
  version: '0'
133
133
  segments:
134
134
  - 0
135
- hash: -1092235871622214733
135
+ hash: 4058162433151782274
136
136
  required_rubygems_version: !ruby/object:Gem::Requirement
137
137
  none: false
138
138
  requirements: