theine 0.0.10 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 44a70acdfb48ffa54a63ec3720c61082f30342d2
4
- data.tar.gz: 3a3c2dd8947da2b1f637f4950c08ca5511dea769
3
+ metadata.gz: 3d99c6739774edb55cc9b94d1a9188207569e942
4
+ data.tar.gz: a207395e8d396715f78fb45820c6b7e05894ca85
5
5
  SHA512:
6
- metadata.gz: d57a7544fd0f61d71a851aba79decded6ef277652a1e3f779c914d32dcf1ea7f12f0f805650714b5f11b597dab272dacb59afea8e671a15028b86ce81ecb15d4
7
- data.tar.gz: fe22098198bb33413f763bd98de9117c2754c6ad3b00ccc4ae7fca432e73e9d1d1159b9e49e4115af076d4aa32d4dbfc0d3a5a7416518ab7dcfd0e30890ac185
6
+ metadata.gz: e4c0f716db657abe2e2eee2e7a9869be61f6364910d4cc9c1ae2125436f2c831c79fe94f957d8795b8bc60c7ce16c371e7af86d0e9f09e3453d69a6b040c1481
7
+ data.tar.gz: 5482ddfff27f95cbf9ce72d18a0190d16f1d7219295f9be116094b7786a7e66547f3acce1dee00d4edcd9a17e05b18225eab1bc3003738c07f58518315f4dff7
data/lib/theine/client.rb CHANGED
@@ -23,19 +23,25 @@ module Theine
23
23
 
24
24
  private
25
25
  def attach_screen
26
- exec("screen -r theine#{@port}")
26
+ # Using vt100 because it does not have smcup/rmcup support,
27
+ # which means the output of the screen will stay shown after
28
+ # screen closes.
29
+ set_vt_100 = "export TERM=vt100; tset"
30
+ erase_screen_message = "echo '\\033[2A\\033[K'"
31
+ exec("#{set_vt_100}; screen -r theine#{@port}; #{erase_screen_message}")
27
32
  end
28
33
 
29
34
  def run_command
30
- case @argv[0]
35
+ argv = @argv.dup
36
+ command = argv.shift
37
+
38
+ case command
31
39
  when "rake"
32
- @argv.shift
33
- @worker.command_rake(@argv)
40
+ @worker.command_rake(argv)
34
41
  when "rspec"
35
- @argv.shift
36
- @worker.command_rspec(@argv)
42
+ @worker.command_rspec(argv)
37
43
  else
38
- @worker.command_rails(@argv)
44
+ @worker.command_rails([command] + argv)
39
45
  end
40
46
  rescue DRb::DRbConnError
41
47
  $stderr.puts "\nTheine closed the connection."
data/lib/theine/server.rb CHANGED
@@ -29,7 +29,7 @@ module Theine
29
29
  puts "(spawn #{port})"
30
30
  spawn("screen", "-d", "-m", "-S", worker_session_name(port),
31
31
  "sh", "-c",
32
- "ruby #{path} #{config.base_port.to_s} #{port.to_s} #{config.rails_root}; read -p 'Press [Enter] to exit...\n'")
32
+ "ruby #{path} #{config.base_port.to_s} #{port.to_s} #{config.rails_root}")
33
33
  @workers_mutex.synchronize { @spawning_workers << port }
34
34
  end
35
35
 
data/lib/theine/worker.rb CHANGED
@@ -4,40 +4,48 @@ require 'drb/drb'
4
4
 
5
5
  module Theine
6
6
  class Worker
7
- attr_reader :command_proc
7
+ attr_reader :port, :balancer
8
8
 
9
- def initialize
10
- @pumps = []
11
- @command_proc = proc { }
12
- end
13
-
14
- def boot
15
- require "#{RAILS_ROOT_PATH}/config/boot"
16
- require "#{RAILS_ROOT_PATH}/config/environment"
17
- end
18
-
19
- def command_rails(argv)
20
- ARGV.clear
21
- ARGV.concat(argv)
22
-
23
- set_command do
9
+ COMMANDS = {
10
+ rails: proc {
24
11
  require 'rails/commands'
25
- end
26
- end
27
-
28
- def command_rake(argv)
29
- set_command do
12
+ },
13
+ rake: proc {
30
14
  ::Rails.application.load_tasks
31
15
  argv.each do |task|
32
16
  ::Rake::Task[task].invoke
33
17
  end
18
+ },
19
+ rspec: proc {
20
+ require 'rspec/core'
21
+ RSpec::Core::Runner.autorun
22
+ }
23
+ }
24
+
25
+ def initialize(port, balancer)
26
+ @port = port
27
+ @balancer = balancer
28
+ @command_proc = proc { }
29
+ end
30
+
31
+ def run
32
+ boot
33
+ begin
34
+ DRb.thread.join
35
+ screen_move_to_bottom
36
+ sleep 0.1 while !screen_attached?
37
+
38
+ puts "command: #{@command_name} #{argv_to_s}"
39
+ @command_proc.call
40
+ ensure
41
+ balancer.worker_done(port)
34
42
  end
35
43
  end
36
44
 
37
- def command_rspec(argv)
38
- set_command do
39
- require 'rspec/core'
40
- ::RSpec::Core::Runner.run(argv, $stderr, $stdout)
45
+ COMMANDS.each_pair do |command_name, command|
46
+ define_method("command_#{command_name}") do |argv|
47
+ set_argv(argv)
48
+ set_command(command_name, &command)
41
49
  end
42
50
  end
43
51
 
@@ -48,35 +56,60 @@ module Theine
48
56
  def stop!
49
57
  exit(1)
50
58
  end
59
+
60
+ def screen_attached?
61
+ !system("screen -ls | grep theine#{@port} | grep Detached > /dev/null")
62
+ end
63
+
64
+ def screen_move_to_bottom
65
+ puts "\033[22B"
66
+ end
67
+
51
68
  private
52
- def set_command(&block)
69
+ def set_command(command_name, &block)
53
70
  rails_reload!
71
+ @command_name = command_name
54
72
  @command_proc = block
55
73
  DRb.stop_service
56
74
  end
57
75
 
76
+ def argv_to_s
77
+ ARGV.map { |arg|
78
+ if arg.include?(" ")
79
+ "\"#{arg}\""
80
+ else
81
+ arg
82
+ end
83
+ }.join(' ')
84
+ end
85
+
86
+ def set_argv(argv)
87
+ ARGV.clear
88
+ ARGV.concat(argv)
89
+ end
90
+
58
91
  def rails_reload!
59
92
  ActionDispatch::Reloader.cleanup!
60
93
  ActionDispatch::Reloader.prepare!
61
94
  end
62
- end
63
- end
64
-
65
- base_port = ARGV[0]
66
- worker_port = ARGV[1].to_i
67
95
 
68
- worker = Theine::Worker.new
96
+ def start_service
97
+ DRb.start_service("druby://localhost:#{@port}", self)
98
+ end
69
99
 
70
- balancer = DRbObject.new_with_uri("druby://localhost:#{base_port}")
71
- balancer.set_worker_pid(worker_port, worker.pid)
100
+ def boot
101
+ balancer.set_worker_pid(port, pid)
72
102
 
73
- worker.boot
74
- DRb.start_service("druby://localhost:#{worker_port}", worker)
75
- balancer.worker_boot(worker_port)
103
+ require "#{RAILS_ROOT_PATH}/config/boot"
104
+ require "#{RAILS_ROOT_PATH}/config/environment"
105
+ start_service
76
106
 
77
- begin
78
- DRb.thread.join
79
- worker.command_proc.call
80
- ensure
81
- balancer.worker_done(worker_port)
107
+ balancer.worker_boot(port)
108
+ end
109
+ end
82
110
  end
111
+
112
+ balancer = DRbObject.new_with_uri("druby://localhost:#{ARGV[0]}")
113
+ worker = Theine::Worker.new(ARGV[1].to_i, balancer)
114
+
115
+ worker.run
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: theine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 0.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Berdajs
@@ -63,7 +63,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
63
63
  version: '0'
64
64
  requirements: []
65
65
  rubyforge_project:
66
- rubygems_version: 2.0.6
66
+ rubygems_version: 2.0.4
67
67
  signing_key:
68
68
  specification_version: 4
69
69
  summary: Theine