remote_run 0.1.3 → 0.1.4

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/Readme.md CHANGED
@@ -12,6 +12,7 @@ machines until all tasks are complete.
12
12
 
13
13
  require 'rubygems'
14
14
  require 'remote_run'
15
+ require 'benchmark'
15
16
 
16
17
  hosts = ["broadway", "wall"]
17
18
  setup = "source ~/.profile; rvm use ree; bundle install;"
@@ -24,6 +25,15 @@ machines until all tasks are complete.
24
25
  runner = Runner.new do |config|
25
26
  config.hosts = hosts
26
27
  config.tasks = tasks
28
+ config.before_task = lambda do |host, task, remote_runner|
29
+ puts "#{host.hostname} is running '#{task.command}' "
30
+ end
31
+ config.around_task = lambda do |&block|
32
+ time = Benchmark.measure do
33
+ block.call
34
+ end
35
+ puts time
36
+ end
27
37
  end
28
38
 
29
39
  # kick off the run
@@ -43,6 +53,12 @@ machines until all tasks are complete.
43
53
  exclude - directories to exclude when rsyncing to remote host (default: [])
44
54
  login_as - the user used to log into ssh (default: current user)
45
55
 
56
+ Callbacks (optional):
57
+ before_run and after_run - the code to be executed before and after the run respectively, receives the remote_run instance as a paramater
58
+ before_task and after_task - the code to be executed before and after each task respectively, receives host, task and the remote_run instance as paramaters
59
+ around_run - the code to execute around the run, receives the block to call
60
+ around_task - the code to execute around each task, receives the block to call
61
+
46
62
 
47
63
  ## Accessible Attributes:
48
64
 
@@ -70,7 +86,7 @@ machines until all tasks are complete.
70
86
 
71
87
  Dependencies:
72
88
  ----------------------------------------------------------------------
73
- * HighLine
89
+ * HighLine
74
90
 
75
91
 
76
92
  License:
@@ -1,6 +1,6 @@
1
1
  module RemoteRun
2
2
  class Configuration
3
- attr_accessor :remote_path, :local_path, :login_as, :exclude, :temp_path, :quiet
3
+ attr_accessor :remote_path, :local_path, :login_as, :exclude, :temp_path, :quiet, :before_task, :after_task, :before_run, :after_run, :around_task, :around_run
4
4
  attr_reader :local_hostname, :identifier, :start_time
5
5
  attr_reader :host_manager, :task_manager
6
6
 
@@ -20,6 +20,12 @@ module RemoteRun
20
20
  @identifier = `echo $RANDOM`.strip
21
21
  @local_hostname = `hostname`.strip
22
22
 
23
+ @before_run = Proc.new{}
24
+ @after_run = Proc.new{}
25
+ @around_run = Proc.new {|&block| block.call }
26
+ @before_task = Proc.new{}
27
+ @after_task = Proc.new{}
28
+ @around_task = Proc.new {|&block| block.call }
23
29
  $runner = self
24
30
  yield self
25
31
  end
@@ -45,7 +51,9 @@ module RemoteRun
45
51
  end
46
52
 
47
53
  def run
48
- Runner.new(self).run
54
+ @before_run.call(self)
55
+ @around_run.call { Runner.new(self).run }
56
+ @after_run.call(self)
49
57
  end
50
58
 
51
59
  private
@@ -12,6 +12,9 @@ module RemoteRun
12
12
  @task_manager = @configuration.task_manager
13
13
  @host_manager = @configuration.host_manager
14
14
  @starting_number_of_tasks = @task_manager.count
15
+ @before_task = @configuration.before_task
16
+ @after_task = @configuration.after_task
17
+ @around_task = @configuration.around_task
15
18
  end
16
19
 
17
20
  def run
@@ -84,15 +87,17 @@ module RemoteRun
84
87
 
85
88
  def start_forked_task(host, task)
86
89
  begin
90
+ @before_task.call(host, task, self)
87
91
  this_host = host.dup
88
92
  unless this_host.copy_codebase
89
93
  @task_manager.add(task)
90
94
  status = 0
91
95
  end
92
- status = this_host.run(task.command)
96
+ @around_task.call { status = this_host.run(task.command) }
93
97
  host.unlock
94
98
  rescue Errno::EPIPE
95
99
  ensure
100
+ @after_task.call(host, task, self)
96
101
  Process.exit!(status)
97
102
  end
98
103
  end
@@ -1,3 +1,3 @@
1
1
  module RemoteRun
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
data/lib/remote_run.rb CHANGED
@@ -3,6 +3,5 @@ require File.join(File.dirname(__FILE__), "remote_run", "host")
3
3
  require File.join(File.dirname(__FILE__), "remote_run", "runner")
4
4
  require File.join(File.dirname(__FILE__), "remote_run", "configuration")
5
5
  require 'highline'
6
-
7
6
  module RemoteRun
8
7
  end
@@ -1,4 +1,24 @@
1
1
  require 'spec_helper'
2
+ describe RemoteRun::Configuration do
3
+ let(:hosts){ ["foo", "bar"] }
4
+ let(:user){ "baz" }
5
+ let!(:pre_run) { double(call: true) }
6
+ let!(:post_run) { double(call: true) }
7
+ subject do
8
+ RemoteRun::Configuration.new do |config|
9
+ config.hosts = hosts
10
+ config.login_as = user
11
+ config.pre_run = pre_run
12
+ config.post_run = post_run
13
+ end
14
+ end
15
+
16
+ it "pre_run should have a callable block" do
17
+ pre_run.should_receive(:call).once
18
+ post_run.should_receive(:call).once
19
+ subject.run
20
+ end
21
+ end
2
22
 
3
23
  describe RemoteRun::Configuration::HostManager do
4
24
  let(:host) { double(:host, is_up?: true, name: "foobar") }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: remote_run
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-10-31 00:00:00.000000000Z
12
+ date: 2011-11-04 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: highline
16
- requirement: &2169342220 !ruby/object:Gem::Requirement
16
+ requirement: &2165476480 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2169342220
24
+ version_requirements: *2165476480
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &2169341540 !ruby/object:Gem::Requirement
27
+ requirement: &2165475960 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *2169341540
35
+ version_requirements: *2165475960
36
36
  description: Can be used as a parallel unit test runner
37
37
  email:
38
38
  - casecommons-dev@googlegroups.com
@@ -71,18 +71,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
71
71
  - - ! '>='
72
72
  - !ruby/object:Gem::Version
73
73
  version: '0'
74
- segments:
75
- - 0
76
- hash: -1981659961289074609
77
74
  required_rubygems_version: !ruby/object:Gem::Requirement
78
75
  none: false
79
76
  requirements:
80
77
  - - ! '>='
81
78
  - !ruby/object:Gem::Version
82
79
  version: '0'
83
- segments:
84
- - 0
85
- hash: -1981659961289074609
86
80
  requirements: []
87
81
  rubyforge_project: remote_run
88
82
  rubygems_version: 1.8.11