crabfarm 0.7.0 → 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/crabfarm/utils/processes.rb +3 -3
- data/lib/crabfarm/version.rb +1 -1
- metadata +17 -4
- data/lib/crabfarm/utils/stream_dumper.rb +0 -142
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c550699098370495349bb242274fee302050ec25
|
4
|
+
data.tar.gz: e422e85f42e800ed20c692e2d68e985962de9ae4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 72c0cfe98b46fec0d071b0d03ccec46307fc2698862aa11a11ed25d0bcd2b65c99502ab14c202b0d4da0c47757353ca4ff824262e36f0d57f84ce37177cb09ac
|
7
|
+
data.tar.gz: d519fa4e7b65275ffac76922654a10199f4e222a35a3789960e1d2baf1cc084260c10f966b7a3b3081aeea1b3e4a82f7aff66af71a19fae5a3a17a1e91df39ea
|
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'childprocess'
|
2
|
-
require '
|
2
|
+
require 'linedump'
|
3
3
|
|
4
4
|
ChildProcess.posix_spawn = true
|
5
5
|
|
@@ -22,8 +22,8 @@ module Crabfarm::Utils
|
|
22
22
|
we.close
|
23
23
|
|
24
24
|
# register log consumers
|
25
|
-
|
26
|
-
|
25
|
+
Linedump.each_line(ro) { |l| _logger.info "[#{_name.upcase}] #{l}" }
|
26
|
+
Linedump.each_line(re) { |l| _logger.warn "[#{_name.upcase}] #{l}" }
|
27
27
|
|
28
28
|
proc
|
29
29
|
end
|
data/lib/crabfarm/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: crabfarm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ignacio Baixas
|
@@ -112,14 +112,14 @@ dependencies:
|
|
112
112
|
requirements:
|
113
113
|
- - ~>
|
114
114
|
- !ruby/object:Gem::Version
|
115
|
-
version: '2
|
115
|
+
version: '1.2'
|
116
116
|
type: :runtime
|
117
117
|
prerelease: false
|
118
118
|
version_requirements: !ruby/object:Gem::Requirement
|
119
119
|
requirements:
|
120
120
|
- - ~>
|
121
121
|
- !ruby/object:Gem::Version
|
122
|
-
version: '2
|
122
|
+
version: '1.2'
|
123
123
|
- !ruby/object:Gem::Dependency
|
124
124
|
name: childprocess
|
125
125
|
requirement: !ruby/object:Gem::Requirement
|
@@ -168,6 +168,20 @@ dependencies:
|
|
168
168
|
- - ~>
|
169
169
|
- !ruby/object:Gem::Version
|
170
170
|
version: '3.2'
|
171
|
+
- !ruby/object:Gem::Dependency
|
172
|
+
name: linedump
|
173
|
+
requirement: !ruby/object:Gem::Requirement
|
174
|
+
requirements:
|
175
|
+
- - ~>
|
176
|
+
- !ruby/object:Gem::Version
|
177
|
+
version: '0.1'
|
178
|
+
type: :runtime
|
179
|
+
prerelease: false
|
180
|
+
version_requirements: !ruby/object:Gem::Requirement
|
181
|
+
requirements:
|
182
|
+
- - ~>
|
183
|
+
- !ruby/object:Gem::Version
|
184
|
+
version: '0.1'
|
171
185
|
- !ruby/object:Gem::Dependency
|
172
186
|
name: selenium-webdriver
|
173
187
|
requirement: !ruby/object:Gem::Requirement
|
@@ -540,7 +554,6 @@ files:
|
|
540
554
|
- lib/crabfarm/utils/processes.rb
|
541
555
|
- lib/crabfarm/utils/resolve.rb
|
542
556
|
- lib/crabfarm/utils/rspec_runner.rb
|
543
|
-
- lib/crabfarm/utils/stream_dumper.rb
|
544
557
|
- lib/crabfarm/utils/webdriver.rb
|
545
558
|
- lib/crabfarm/version.rb
|
546
559
|
homepage: https://github.com/platanus/crabfarm-gem
|
@@ -1,142 +0,0 @@
|
|
1
|
-
require 'thwait'
|
2
|
-
|
3
|
-
module Crabfarm::Utils
|
4
|
-
|
5
|
-
class StreamDumper
|
6
|
-
|
7
|
-
class Reload < StandardError; end
|
8
|
-
|
9
|
-
def self.consumer
|
10
|
-
@@consumer ||= self.new
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.register_stream(_stream, &_block)
|
14
|
-
consumer.register_stream _stream, &_block
|
15
|
-
consumer.restart
|
16
|
-
end
|
17
|
-
|
18
|
-
def initialize
|
19
|
-
@streams = []
|
20
|
-
@lock = Mutex.new
|
21
|
-
@worker = nil
|
22
|
-
end
|
23
|
-
|
24
|
-
def register_stream(_stream, &_block)
|
25
|
-
@lock.synchronize { @streams << Wrapper.new(_stream, _block) }
|
26
|
-
end
|
27
|
-
|
28
|
-
def restart
|
29
|
-
@lock.synchronize do
|
30
|
-
if @worker and @worker.alive?
|
31
|
-
@worker.raise Reload # signal worker to reload streams
|
32
|
-
else
|
33
|
-
@worker = load_worker
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
private
|
39
|
-
|
40
|
-
def load_worker
|
41
|
-
Thread.new do
|
42
|
-
looped = 0
|
43
|
-
begin
|
44
|
-
while @streams.count > 0
|
45
|
-
all_streams = dump_streams
|
46
|
-
result = IO.select(all_streams << $stdin, [], all_streams)
|
47
|
-
if result
|
48
|
-
process_ready_streams result[0]
|
49
|
-
discard_errored_streams result[2]
|
50
|
-
end
|
51
|
-
looped += 1
|
52
|
-
end
|
53
|
-
rescue Reload
|
54
|
-
retry
|
55
|
-
rescue SystemExit
|
56
|
-
# nothing
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
def process_ready_streams(_streams)
|
62
|
-
_streams.each do |stream|
|
63
|
-
wrapper = find_stream_wrapper stream
|
64
|
-
if wrapper
|
65
|
-
wrapper.process_lines
|
66
|
-
remove_wrapper wrapper, :eof if wrapper.eof?
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
def discard_errored_streams(_streams)
|
72
|
-
_streams.each do |stream|
|
73
|
-
wrapper = find_stream_wrapper stream
|
74
|
-
remove_wrapper wrapper, :error if wrapper
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
def find_stream_wrapper(_stream)
|
79
|
-
@streams.find { |s| s.stream == _stream }
|
80
|
-
end
|
81
|
-
|
82
|
-
def remove_wrapper(_wrapper, _reason)
|
83
|
-
@lock.synchronize { @streams.delete _wrapper }
|
84
|
-
end
|
85
|
-
|
86
|
-
def dump_streams
|
87
|
-
@streams.map(&:stream)
|
88
|
-
end
|
89
|
-
|
90
|
-
class Wrapper
|
91
|
-
|
92
|
-
MAX_LENGTH = 2048
|
93
|
-
|
94
|
-
attr_reader :stream
|
95
|
-
|
96
|
-
def initialize(_stream, _block)
|
97
|
-
@stream = _stream
|
98
|
-
@block = _block
|
99
|
-
@buffer = []
|
100
|
-
@eof = false
|
101
|
-
end
|
102
|
-
|
103
|
-
def eof?
|
104
|
-
@eof
|
105
|
-
end
|
106
|
-
|
107
|
-
def process_lines
|
108
|
-
begin
|
109
|
-
loop do
|
110
|
-
chunk = @stream.read_nonblock(MAX_LENGTH)
|
111
|
-
process_chunk chunk
|
112
|
-
end
|
113
|
-
rescue IO::WaitReadable
|
114
|
-
# nothing, just stop looping
|
115
|
-
rescue EOFError
|
116
|
-
@eof = true
|
117
|
-
rescue Exception => exc
|
118
|
-
puts "Error in stream consumer: #{exc}"
|
119
|
-
@eof = true
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
def process_chunk(_chunk)
|
124
|
-
index = _chunk.index $/
|
125
|
-
|
126
|
-
unless index.nil?
|
127
|
-
head = _chunk[0..index-1]
|
128
|
-
tail = _chunk[index+1..-1]
|
129
|
-
|
130
|
-
@block.call(@buffer.join + head)
|
131
|
-
@buffer.clear
|
132
|
-
|
133
|
-
process_chunk tail
|
134
|
-
else
|
135
|
-
@buffer << _chunk
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
end
|
140
|
-
|
141
|
-
end
|
142
|
-
end
|