/
processable.rb
53 lines (42 loc) · 1.25 KB
/
processable.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
module Capistrano
module Processable
module SessionAssociation
def self.on(exception, session)
unless exception.respond_to?(:session)
exception.extend(self)
exception.session = session
end
return exception
end
attr_accessor :session
end
def process_iteration(wait=nil, &block)
ensure_each_session { |session| session.preprocess }
return false if block && !block.call(self)
readers = sessions.map { |session| session.listeners.keys }.flatten.reject { |io| io.closed? }
writers = readers.select { |io| io.respond_to?(:pending_write?) && io.pending_write? }
if readers.any? || writers.any?
readers, writers, = IO.select(readers, writers, nil, wait)
end
if readers
ensure_each_session do |session|
ios = session.listeners.keys
session.postprocess(ios & readers, ios & writers)
end
end
true
end
def ensure_each_session
errors = []
sessions.each do |session|
begin
yield session
rescue Exception => error
errors << SessionAssociation.on(error, session)
end
end
raise errors.first if errors.any?
sessions
end
end
end