carnivore-files 0.3.2 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9885c8a235402d43bae2dc3f5d84598eb0f375b6
4
- data.tar.gz: aca92773742ce3ca902354953862014b5fe93f79
3
+ metadata.gz: 21f87b83875a9836746133d6a3a25977a3828f1d
4
+ data.tar.gz: 2eae7f95014052a60389f86335dde13bab1028d4
5
5
  SHA512:
6
- metadata.gz: d30c076521bc560341c3a9f7783159a84ea01f778b5a8e418a123f99a7846e977ec3732c2cbba3a3601c0071a4cf062ff4b4a6c95bebd30b38dc293fd3228197
7
- data.tar.gz: 1234d420d862b4d228ed0584fa333a6b8bd4ba7d317519d5d902f5ef2151065c57904edc2dd63495a69350494b0d86155d4b49ed8296642878647f17ffe2e79b
6
+ metadata.gz: d7292143d29a6b5f53aa0841b669e1c945557b17d91dac81c5694babb72750e5759624be7f64cc4719fbcfcb31dde0061e6f36454147a5c15810c4b5252933b6
7
+ data.tar.gz: f547ded42f15317e74ca1c59294b2b45da6df929b8b083b919e42ec6da5f2726ea931f287f58582e227ede4161da434f208f4dc1e90ea9079a6bde7966d9d617
@@ -1,3 +1,7 @@
1
+ # v0.5.0
2
+ * Update to latest carnivore
3
+ * Refactor implementations
4
+
1
5
  # v0.3.2
2
6
  * Reset position prior to read
3
7
 
@@ -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.add_runtime_dependency 'carnivore', '>= 0.1.8'
14
- s.add_runtime_dependency 'sleepy_penguin'
13
+ s.add_runtime_dependency 'carnivore', '>= 1.0.0', '< 2.0.0'
14
+ s.add_runtime_dependency 'sleepy_penguin', '~> 3.4'
15
15
  s.add_development_dependency 'pry'
16
16
  s.files = Dir['{lib}/**/**/*'] + %w(carnivore-files.gemspec README.md CHANGELOG.md)
17
17
  end
@@ -9,18 +9,17 @@ module Carnivore
9
9
  attr_reader :path
10
10
  # @return [Symbol] registry name of fetcher
11
11
  attr_reader :fetcher
12
-
13
- trap_exit :fetcher_failure
14
- finalizer :fetcher_destroyer
12
+ # @return [Queue] queue to hold messages
13
+ attr_reader :message_queue
15
14
 
16
15
  # Setup source
17
16
  #
18
17
  # @param args [Hash]
19
18
  # @option args [String] :path path to file
20
19
  # @option args [Symbol] :foundation underlying file interaction library
21
- # @option args [Celluloid::Actor] :notify_actor actor to notify on line receive
22
20
  def setup(*_)
23
21
  @path = ::File.expand_path(args[:path])
22
+ @message_queue = Queue.new
24
23
  unless(args[:foundation])
25
24
  args[:foundation] = RUBY_PLATFORM == 'java' ? :poll : :penguin
26
25
  end
@@ -28,37 +27,18 @@ module Carnivore
28
27
 
29
28
  # Start the line fetcher
30
29
  def connect
31
- @fetcher_name = "log_fetcher_#{name}".to_sym
32
30
  case args[:foundation].to_sym
33
31
  when :poll
34
- @fetcher = Carnivore::Files::Util::Fetcher::Poll.new(args)
32
+ @fetcher = Carnivore::Files::Util::Fetcher::Poll.new(args.merge(:queue => message_queue))
35
33
  else
36
- @fetcher = Carnivore::Files::Util::Fetcher::Penguin.new(args)
34
+ @fetcher = Carnivore::Files::Util::Fetcher::Penguin.new(args.merge(:queue => message_queue))
37
35
  end
38
- self.link fetcher
39
36
  fetcher.async.start_fetcher
40
37
  end
41
38
 
42
- # Restart file collector if unexpectedly failed
43
- #
44
- # @param object [Actor] crashed actor
45
- # @param reason [Exception, NilClass]
46
- def fetcher_failure(object, reason)
47
- if(reason && object == fetcher)
48
- error "File message collector unexpectedly failed: #{reason} (restarting)"
49
- connect
50
- end
51
- end
52
-
53
- def fetcher_destroyer
54
- if(fetcher && fetcher.alive?)
55
- fetcher.terminate
56
- end
57
- end
58
-
59
39
  # @return [Array<Hash>] return messages
60
- def receive(*args)
61
- format_message(Celluloid::Future.new{ fetcher.messages.pop }.value)
40
+ def receive(*_)
41
+ defer{ message_queue.pop }
62
42
  end
63
43
 
64
44
  # Send payload
@@ -10,7 +10,8 @@ module Carnivore
10
10
  autoload :Poll, 'carnivore-files/util/poll'
11
11
  autoload :Penguin, 'carnivore-files/util/penguin'
12
12
 
13
- include Celluloid
13
+ include Zoidberg::SoftShell
14
+ include Zoidberg::Supervise
14
15
  include Carnivore::Utils::Logging
15
16
 
16
17
  # @return [String] path to file
@@ -28,12 +29,11 @@ module Carnivore
28
29
  # @param args [Hash] initialization args
29
30
  # @option args [String] :path path to file
30
31
  # @option args [String] :delimiter string delimiter to break messages
31
- # @option args [Celluloid::Actor] :notify_actor actor to be notified on new messages
32
32
  def initialize(args={})
33
33
  @leftover = ''
34
34
  @path = ::File.expand_path(args[:path])
35
35
  @delimiter = args.fetch(:delimiter, "\n")
36
- @messages = Queue.new
36
+ @messages = args.fetch(:queue, Queue.new)
37
37
  end
38
38
 
39
39
  # Start the line fetcher
@@ -57,10 +57,9 @@ module Carnivore
57
57
  def retrieve_lines
58
58
  if(io)
59
59
  io.pos = @history_pos if @history_pos
60
- data = io.read(4096)
60
+ @leftover << io.read(4096).to_s
61
61
  while(data = io.read(4096))
62
- @leftover << data
63
- data = io.read(4096)
62
+ @leftover << data.to_s
64
63
  end
65
64
  @history_pos = io.pos
66
65
  result = @leftover.split(delimiter)
@@ -77,6 +76,7 @@ module Carnivore
77
76
  def build_io
78
77
  unless(io)
79
78
  if(::File.exists?(path))
79
+ @history_pos = 0
80
80
  @io = ::File.open(path, 'r')
81
81
  unless(@waited)
82
82
  @io.seek(0, ::IO::SEEK_END) # fast-forward to EOF
@@ -5,7 +5,6 @@ module Carnivore
5
5
  module Util
6
6
  class Fetcher
7
7
 
8
-
9
8
  # NIO based fetcher
10
9
  class Penguin < Fetcher
11
10
  # @return [SP::Inotify]
@@ -27,7 +26,7 @@ module Carnivore
27
26
  loop do
28
27
  build_io
29
28
  notify.each do |event|
30
- Celluloid::Future.new{ event.events }.value.each do |ev|
29
+ defer{ event.events }.each do |ev|
31
30
  case ev
32
31
  when :MODIFY
33
32
  retrieve_lines.each do |l|
@@ -47,7 +46,6 @@ module Carnivore
47
46
  end
48
47
  end
49
48
 
50
-
51
49
  private
52
50
 
53
51
  # Build the IO and monitor
@@ -84,7 +82,7 @@ module Carnivore
84
82
  notify_descriptors[:file_wait] = notify.add_watch(directory, :OPEN)
85
83
  until(notified)
86
84
  warn "Waiting for file to appear (#{path})"
87
- event = Celluloid::Future.new{ notify.take }.value
85
+ event = defer{ notify.take }
88
86
  notified = ::File.exists?(path)
89
87
  end
90
88
  notify.rm_watch(notify_descriptors.delete(:file_wait))
@@ -1,6 +1,6 @@
1
1
  module Carnivore
2
2
  module Files
3
3
  # Current version of library
4
- VERSION = Gem::Version.new('0.3.2')
4
+ VERSION = Gem::Version.new('0.5.0')
5
5
  end
6
6
  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.3.2
4
+ version: 0.5.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-05-01 00:00:00.000000000 Z
11
+ date: 2015-09-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: carnivore
@@ -16,28 +16,34 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 0.1.8
19
+ version: 1.0.0
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: 2.0.0
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
27
  - - ">="
25
28
  - !ruby/object:Gem::Version
26
- version: 0.1.8
29
+ version: 1.0.0
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: 2.0.0
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: sleepy_penguin
29
35
  requirement: !ruby/object:Gem::Requirement
30
36
  requirements:
31
- - - ">="
37
+ - - "~>"
32
38
  - !ruby/object:Gem::Version
33
- version: '0'
39
+ version: '3.4'
34
40
  type: :runtime
35
41
  prerelease: false
36
42
  version_requirements: !ruby/object:Gem::Requirement
37
43
  requirements:
38
- - - ">="
44
+ - - "~>"
39
45
  - !ruby/object:Gem::Version
40
- version: '0'
46
+ version: '3.4'
41
47
  - !ruby/object:Gem::Dependency
42
48
  name: pry
43
49
  requirement: !ruby/object:Gem::Requirement