carnivore-files 0.2.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/carnivore-files.gemspec +3 -3
- data/lib/carnivore-files/carn_file.rb +3 -3
- data/lib/carnivore-files/util/fetcher.rb +1 -1
- data/lib/carnivore-files/util/poll.rb +60 -0
- data/lib/carnivore-files/version.rb +1 -1
- metadata +5 -5
- data/lib/carnivore-files/util/nio.rb +0 -98
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c2ac46989db78c983618bce2a65e1fecc092da4f
|
4
|
+
data.tar.gz: dab411187db6ba936a6755e98f3dbebe2e9ed09b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a4d63b3c974d2382e3fbf57f6503fb91a1250ee71451f65c24c418e6841973655b62a99e4a40cefb640b901190384568e1495dc11243c949c08f95588ee9b7d2
|
7
|
+
data.tar.gz: a0c601612f8c5188c39581dd9a3958142bb6918759e72a553ceacd9a9b12b41dc7759ac51912d382292085d72915aac71216eeb4b2d40491aeef832266d64e7f
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
# v0.3.0
|
2
|
+
* Remove nio based fetcher implementation
|
3
|
+
* Add polling based fetcher implementation
|
4
|
+
|
5
|
+
_NOTE: This release removes nio4r. The source still behaves the same, but
|
6
|
+
if specific functionality provided by nio4r was required, it is no
|
7
|
+
longer available._
|
8
|
+
|
1
9
|
# v0.2.2
|
2
10
|
* Clean up file content fetcher implementations
|
3
11
|
|
data/carnivore-files.gemspec
CHANGED
@@ -10,8 +10,8 @@ spec = Gem::Specification.new do |s|
|
|
10
10
|
s.description = 'Carnivore file source'
|
11
11
|
s.license = 'Apache 2.0'
|
12
12
|
s.require_path = 'lib'
|
13
|
-
s.
|
14
|
-
s.
|
15
|
-
s.
|
13
|
+
s.add_runtime_dependency 'carnivore', '>= 0.1.8'
|
14
|
+
s.add_runtime_dependency 'sleepy_penguin'
|
15
|
+
s.add_development_dependency 'pry'
|
16
16
|
s.files = Dir['{lib}/**/**/*'] + %w(carnivore-files.gemspec README.md CHANGELOG.md)
|
17
17
|
end
|
@@ -22,7 +22,7 @@ module Carnivore
|
|
22
22
|
def setup(*_)
|
23
23
|
@path = ::File.expand_path(args[:path])
|
24
24
|
unless(args[:foundation])
|
25
|
-
args[:foundation] = RUBY_PLATFORM == 'java' ? :
|
25
|
+
args[:foundation] = RUBY_PLATFORM == 'java' ? :poll : :penguin
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
@@ -30,8 +30,8 @@ module Carnivore
|
|
30
30
|
def connect
|
31
31
|
@fetcher_name = "log_fetcher_#{name}".to_sym
|
32
32
|
case args[:foundation].to_sym
|
33
|
-
when :
|
34
|
-
@fetcher = Carnivore::Files::Util::Fetcher::
|
33
|
+
when :poll
|
34
|
+
@fetcher = Carnivore::Files::Util::Fetcher::Poll.new(args)
|
35
35
|
else
|
36
36
|
@fetcher = Carnivore::Files::Util::Fetcher::Penguin.new(args)
|
37
37
|
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'carnivore-files'
|
2
|
+
|
3
|
+
module Carnivore
|
4
|
+
module Files
|
5
|
+
module Util
|
6
|
+
class Fetcher
|
7
|
+
|
8
|
+
# Polling fetcher
|
9
|
+
class Poll < Fetcher
|
10
|
+
|
11
|
+
# Start the fetcher
|
12
|
+
def start_fetcher
|
13
|
+
loop do
|
14
|
+
build_io
|
15
|
+
ino = io.stat.ino
|
16
|
+
retrieve_lines.each do |line|
|
17
|
+
self.messages << line
|
18
|
+
end
|
19
|
+
pos = io.pos
|
20
|
+
sleep(1)
|
21
|
+
begin
|
22
|
+
if(io.size < pos || ino != File.stat(path).ino)
|
23
|
+
destroy_io
|
24
|
+
@waited = true
|
25
|
+
end
|
26
|
+
rescue Errno::ENOENT
|
27
|
+
destroy_io
|
28
|
+
@waited = true
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# Destroy the IO instance and monitor
|
34
|
+
#
|
35
|
+
# @return [TrueClass]
|
36
|
+
def destroy_io
|
37
|
+
if(io)
|
38
|
+
io.close
|
39
|
+
@io = nil
|
40
|
+
end
|
41
|
+
true
|
42
|
+
end
|
43
|
+
|
44
|
+
# Wait helper for file to appear (2 second intervals)
|
45
|
+
#
|
46
|
+
# @return [TrueClass]
|
47
|
+
def wait_for_file
|
48
|
+
warn "Waiting for file to appear (#{path})"
|
49
|
+
until(::File.exists?(path))
|
50
|
+
@waited = true
|
51
|
+
sleep(2)
|
52
|
+
end
|
53
|
+
info "File has appeared (#{path})!"
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: carnivore-files
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Roberts
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-03-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: carnivore
|
@@ -39,13 +39,13 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: pry
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
|
-
type: :
|
48
|
+
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
@@ -64,8 +64,8 @@ files:
|
|
64
64
|
- lib/carnivore-files.rb
|
65
65
|
- lib/carnivore-files/carn_file.rb
|
66
66
|
- lib/carnivore-files/util/fetcher.rb
|
67
|
-
- lib/carnivore-files/util/nio.rb
|
68
67
|
- lib/carnivore-files/util/penguin.rb
|
68
|
+
- lib/carnivore-files/util/poll.rb
|
69
69
|
- lib/carnivore-files/version.rb
|
70
70
|
homepage: https://github.com/carnivore-rb/carnivore-files
|
71
71
|
licenses:
|
@@ -1,98 +0,0 @@
|
|
1
|
-
require 'nio'
|
2
|
-
|
3
|
-
module Carnivore
|
4
|
-
module Files
|
5
|
-
module Util
|
6
|
-
class Fetcher
|
7
|
-
|
8
|
-
# NIO based fetcher
|
9
|
-
class Nio < Fetcher
|
10
|
-
|
11
|
-
# @return [NIO::Monitor]
|
12
|
-
attr_accessor :monitor
|
13
|
-
# @return [NIO::Selector]
|
14
|
-
attr_accessor :selector
|
15
|
-
|
16
|
-
# Create new instance
|
17
|
-
#
|
18
|
-
# @param args [Hash] initialization arguments (unused)
|
19
|
-
def initialize(args={})
|
20
|
-
super
|
21
|
-
@selector = NIO::Selector.new
|
22
|
-
every(5) do
|
23
|
-
check_file
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
# Start the fetcher
|
28
|
-
def start_fetcher
|
29
|
-
loop do
|
30
|
-
build_io
|
31
|
-
messages = nil
|
32
|
-
Celluloid::Future.new{ selector.select }.value.each do |mon|
|
33
|
-
retrieve_lines.each do |l|
|
34
|
-
self.messages << l
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
private
|
41
|
-
|
42
|
-
# Check for file and destroy monitor if file has changed
|
43
|
-
def check_file
|
44
|
-
if(io)
|
45
|
-
begin
|
46
|
-
unless(io.stat.ino == ::File.stat(path).ino)
|
47
|
-
destroy_io
|
48
|
-
@waited = true
|
49
|
-
end
|
50
|
-
rescue Errno::ENOENT
|
51
|
-
destroy_io
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
# Build the IO instance if found
|
57
|
-
#
|
58
|
-
# @return [TrueClass]
|
59
|
-
def build_io
|
60
|
-
result = super
|
61
|
-
if(result && @monitor.nil?)
|
62
|
-
@monitor = selector.register(io, :r)
|
63
|
-
end
|
64
|
-
result
|
65
|
-
end
|
66
|
-
|
67
|
-
# Destroy the IO instance and monitor
|
68
|
-
#
|
69
|
-
# @return [TrueClass]
|
70
|
-
def destroy_io
|
71
|
-
if(monitor)
|
72
|
-
selector.deregister(monitor)
|
73
|
-
@monitor = nil
|
74
|
-
end
|
75
|
-
if(io)
|
76
|
-
io.close
|
77
|
-
@io = nil
|
78
|
-
end
|
79
|
-
true
|
80
|
-
end
|
81
|
-
|
82
|
-
# Wait helper for file to appear (5 sleep second intervals)
|
83
|
-
#
|
84
|
-
# @return [TrueClass]
|
85
|
-
def wait_for_file
|
86
|
-
warn "Waiting for file to appear (#{path})"
|
87
|
-
until(::File.exists?(path))
|
88
|
-
@waited = true
|
89
|
-
sleep(5)
|
90
|
-
end
|
91
|
-
info "File has appeared (#{path})!"
|
92
|
-
end
|
93
|
-
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|