fezzik 0.8.2 → 0.8.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +23 -5
- data/fezzik.gemspec +1 -1
- data/lib/fezzik/base.rb +7 -5
- data/lib/fezzik/host_task.rb +4 -3
- data/lib/fezzik/version.rb +1 -1
- metadata +5 -8
data/README.md
CHANGED
@@ -56,12 +56,14 @@ $ fez prod echo
|
|
56
56
|
The `host_task` method is similar to Rake's `task` in functionality, but has a slightly different API due to
|
57
57
|
its additional options. A host task is defined with a name some (optional) options. The three primary ones are
|
58
58
|
`:args`, `:deps`, and `:roles`. `:args` and `:deps` correspond to Rake's task arguments and task dependencies,
|
59
|
-
and `:roles` is a Fezzik-specific option explained later. There are also three additional options which
|
60
|
-
|
59
|
+
and `:roles` is a Fezzik-specific option explained later. There are also three additional options which can be
|
60
|
+
passed to [Weave](https://github.com/cespare/weave), Fezzik's underlying ssh library, by specifying them in a
|
61
|
+
`:weave_options` hash. They control how host tasks run concurrently:
|
61
62
|
|
62
|
-
- `:num_threads`:
|
63
|
-
|
64
|
-
- `:
|
63
|
+
- `:num_threads`: The number of threads used to run this task in parallel, or `:unlimited` to use a thread for
|
64
|
+
every host. Defaults to 10.
|
65
|
+
- `:serial`: Whether to process the command for each connection one at a time. Defaults to false.
|
66
|
+
- `:batch_by`: If set, group the connections into batches of no more than this value.
|
65
67
|
|
66
68
|
A Rake task that looks like this:
|
67
69
|
|
@@ -80,6 +82,22 @@ host_task :echo, :args => [:arg1, :arg2],
|
|
80
82
|
end
|
81
83
|
```
|
82
84
|
|
85
|
+
And with Weave options:
|
86
|
+
|
87
|
+
```ruby
|
88
|
+
host_task :echo, :args => [:arg1, :arg2],
|
89
|
+
:deps => [:dep1, :dep2],
|
90
|
+
:weave_options => {:num_threads => 20} do |t, args|
|
91
|
+
...
|
92
|
+
end
|
93
|
+
```
|
94
|
+
|
95
|
+
To avoid repeating the same `weave_options` on every host_task, set `Fezzik.default_weave_options`, which
|
96
|
+
will be merged with the `:weave_options` hash of a `host_task`.
|
97
|
+
|
98
|
+
```ruby
|
99
|
+
Fezzik.default_weave_options = { :num_threads => :unlimited }
|
100
|
+
```
|
83
101
|
|
84
102
|
## Deployments
|
85
103
|
|
data/fezzik.gemspec
CHANGED
data/lib/fezzik/base.rb
CHANGED
@@ -2,6 +2,9 @@ module Fezzik
|
|
2
2
|
def self.activated=(value) @activated = value end
|
3
3
|
def self.activated?() @activated || false end
|
4
4
|
|
5
|
+
def self.default_weave_options() @@default_weave_options ||= {} end
|
6
|
+
def self.default_weave_options=(options) @@default_weave_options = options end
|
7
|
+
|
5
8
|
def self.set(name, value)
|
6
9
|
@@settings ||= {}
|
7
10
|
|
@@ -34,16 +37,15 @@ module Fezzik
|
|
34
37
|
host_task(name, { :args => Array(args), :deps => Array(deps), :roles => Array(roles) }, &block)
|
35
38
|
end
|
36
39
|
|
37
|
-
WEAVE_OPTIONS = [:num_threads, :serial, :batch_by]
|
38
|
-
|
39
40
|
def self.host_task(name, options = {}, &block)
|
40
41
|
options = {
|
41
42
|
:args => [],
|
42
43
|
:deps => [],
|
43
|
-
:roles => []
|
44
|
+
:roles => [],
|
45
|
+
:weave_options => {}
|
44
46
|
}.merge(options)
|
45
|
-
weave_options = options
|
46
|
-
options.
|
47
|
+
weave_options = options[:weave_options]
|
48
|
+
options.delete(:weave_options)
|
47
49
|
options.each { |key, value| options[key] = Array(value) }
|
48
50
|
t = HostTask.define_task(name, { options[:args] => options[:deps] }, &block)
|
49
51
|
t.roles += options[:roles]
|
data/lib/fezzik/host_task.rb
CHANGED
@@ -17,12 +17,14 @@ module Fezzik
|
|
17
17
|
def execute(args = nil)
|
18
18
|
return if Rake.application.options.dryrun
|
19
19
|
|
20
|
+
merged_weave_options = Fezzik.default_weave_options.merge(@weave_options).merge(:args => [self, args])
|
21
|
+
|
20
22
|
if @roles.empty?
|
21
23
|
hosts = Fezzik.get(:domain).map { |domain| "#{Fezzik.get(:user)}@#{domain}" }
|
22
24
|
@@connection_pool ||= Weave::ConnectionPool.new
|
23
25
|
@host_actions.each do |action|
|
24
26
|
begin
|
25
|
-
@@connection_pool.execute_with(hosts,
|
27
|
+
@@connection_pool.execute_with(hosts, merged_weave_options, &action)
|
26
28
|
rescue Weave::Error => e
|
27
29
|
STDERR.puts "Error running command in HostTask '#{@name}':"
|
28
30
|
abort e.message
|
@@ -36,8 +38,7 @@ module Fezzik
|
|
36
38
|
@@role_connection_pools[role] ||= Weave::ConnectionPool.new
|
37
39
|
@host_actions.each do |action|
|
38
40
|
begin
|
39
|
-
@@role_connection_pools[role].execute_with(hosts,
|
40
|
-
&action)
|
41
|
+
@@role_connection_pools[role].execute_with(hosts, merged_weave_options, &action)
|
41
42
|
rescue Weave::Error => e
|
42
43
|
STDERR.puts "Error running command in HostTask '#{@name}' with role '#{role}':"
|
43
44
|
abort e.message
|
data/lib/fezzik/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fezzik
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -33,17 +33,17 @@ dependencies:
|
|
33
33
|
requirement: !ruby/object:Gem::Requirement
|
34
34
|
none: false
|
35
35
|
requirements:
|
36
|
-
- -
|
36
|
+
- - ~>
|
37
37
|
- !ruby/object:Gem::Version
|
38
|
-
version: 0.
|
38
|
+
version: 1.0.0
|
39
39
|
type: :runtime
|
40
40
|
prerelease: false
|
41
41
|
version_requirements: !ruby/object:Gem::Requirement
|
42
42
|
none: false
|
43
43
|
requirements:
|
44
|
-
- -
|
44
|
+
- - ~>
|
45
45
|
- !ruby/object:Gem::Version
|
46
|
-
version: 0.
|
46
|
+
version: 1.0.0
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: scope
|
49
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -105,9 +105,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
105
105
|
- - ! '>='
|
106
106
|
- !ruby/object:Gem::Version
|
107
107
|
version: '0'
|
108
|
-
segments:
|
109
|
-
- 0
|
110
|
-
hash: -3699193931790573527
|
111
108
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
109
|
none: false
|
113
110
|
requirements:
|