public
Description: Remote multi-server automation tool
Homepage: http://www.capify.org
Clone URL: git://github.com/jamis/capistrano.git
Search Repo:
wrap the SFTP instantiation so that it can occur in parallel for better 
performance
jamis (author)
Thu Apr 24 21:20:33 -0700 2008
commit  cedcff2a65b146a51f70c2851f4f77cd7086fff4
tree    af820efc6da2b2a5f73731ee17161e3930785082
parent  38c1b5728c335fad5285ee06c02bc553d56197be
...
134
135
136
137
138
139
140
141
142
143
144
145
146
147
 
 
 
 
 
 
148
149
150
151
152
153
154
155
156
157
 
 
 
 
 
 
 
 
 
 
 
158
159
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
160
161
162
...
164
165
166
167
168
 
169
170
171
...
134
135
136
 
 
 
 
 
 
 
 
 
 
 
137
138
139
140
141
142
143
 
 
144
145
 
 
 
 
 
146
147
148
149
150
151
152
153
154
155
156
157
 
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
...
188
189
190
 
 
191
192
193
194
0
@@ -134,29 +134,53 @@ module Capistrano
0
         return channel
0
       end
0
 
0
- def prepare_sftp_transfer(from, to, session)
0
- # FIXME: connect! is a synchronous operation, do this async and then synchronize all at once
0
- sftp = Net::SFTP::Session.new(session).connect!
0
-
0
- real_callback = Proc.new do |event, op, *args|
0
- if callback
0
- callback.call(event, op, *args)
0
- elsif event == :open
0
- logger.trace "[#{op[:host]}] #{args[0].remote}"
0
- elsif event == :finish
0
- logger.trace "[#{op[:host]}] done"
0
+ class SFTPTransferWrapper
0
+ attr_reader :operation
0
+
0
+ def initialize(session, &callback)
0
+ Net::SFTP::Session.new(session) do |sftp|
0
+ @operation = callback.call(sftp)
0
           end
0
-
0
- op[:channel].close if event == :finish
0
         end
0
 
0
- opts = options.dup
0
- opts[:properties] = (opts[:properties] || {}).merge(
0
- :server => session.xserver,
0
- :host => session.xserver.host,
0
- :channel => sftp.channel)
0
+ def active?
0
+ @operation.nil? || @operation.active?
0
+ end
0
+
0
+ def [](key)
0
+ @operation[key]
0
+ end
0
+
0
+ def []=(key, value)
0
+ @operation[key] = value
0
+ end
0
 
0
- operation = case direction
0
+ def abort!
0
+ @operation.abort!
0
+ end
0
+ end
0
+
0
+ def prepare_sftp_transfer(from, to, session)
0
+ SFTPTransferWrapper.new(session) do |sftp|
0
+ real_callback = Proc.new do |event, op, *args|
0
+ if callback
0
+ callback.call(event, op, *args)
0
+ elsif event == :open
0
+ logger.trace "[#{op[:host]}] #{args[0].remote}"
0
+ elsif event == :finish
0
+ logger.trace "[#{op[:host]}] done"
0
+ end
0
+
0
+ op[:channel].close if event == :finish
0
+ end
0
+
0
+ opts = options.dup
0
+ opts[:properties] = (opts[:properties] || {}).merge(
0
+ :server => session.xserver,
0
+ :host => session.xserver.host,
0
+ :channel => sftp.channel)
0
+
0
+ case direction
0
           when :up
0
             sftp.upload(from, to, opts, &real_callback)
0
           when :down
0
@@ -164,8 +188,7 @@ module Capistrano
0
           else
0
             raise ArgumentError, "unsupported transfer direction: #{direction.inspect}"
0
           end
0
-
0
- return operation
0
+ end
0
       end
0
 
0
       def normalize(argument, session)

Comments

    No one has commented yet.