eventmachine-tail 0.6.2 → 0.6.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/em/filetail.rb +20 -4
  2. data/lib/em/globwatcher.rb +18 -4
  3. metadata +4 -4
@@ -46,6 +46,9 @@ class EventMachine::FileTail
46
46
 
47
47
  # The current file read position
48
48
  attr_reader :position
49
+
50
+ # If this tail is closed
51
+ attr_reader :closed
49
52
 
50
53
  # Check interval when checking symlinks for changes. This is only useful
51
54
  # when you are actually tailing symlinks.
@@ -78,6 +81,8 @@ class EventMachine::FileTail
78
81
  @want_reopen = false
79
82
  @reopen_on_eof = false
80
83
  @symlink_timer = nil
84
+ @missing_file_check_timer = nil
85
+ @read_timer = nil
81
86
  @symlink_target = nil
82
87
  @symlink_stat = nil
83
88
 
@@ -200,11 +205,22 @@ class EventMachine::FileTail
200
205
  public
201
206
  def close
202
207
  @closed = true
208
+ @want_read = false
203
209
  EM.schedule do
210
+ @watch.stop_watching if @watch
211
+ EventMachine::cancel_timer(@read_timer) if @read_timer
212
+ @symlink_timer.cancel if @symlink_timer
213
+ @missing_file_check_timer.cancel if @missing_file_check_timer
204
214
  @file.close if @file
205
215
  end
206
216
  end # def close
207
-
217
+
218
+ # More rubyesque way of checking if this tail is closed
219
+ public
220
+ def closed?
221
+ @closed
222
+ end
223
+
208
224
  # Watch our file.
209
225
  private
210
226
  def watch
@@ -244,7 +260,7 @@ class EventMachine::FileTail
244
260
  def schedule_next_read
245
261
  if !@want_read
246
262
  @want_read = true
247
- EventMachine::add_timer(@naptime) do
263
+ @read_timer = EventMachine::add_timer(@naptime) do
248
264
  @want_read = false
249
265
  read
250
266
  end
@@ -319,12 +335,12 @@ class EventMachine::FileTail
319
335
  rescue Errno::ENOENT
320
336
  # The file disappeared. Wait for it to reappear.
321
337
  # This can happen if it was deleted or moved during log rotation.
322
- timer = EM::PeriodicTimer.new(@missing_file_check_interval) do
338
+ @missing_file_check_timer = EM::PeriodicTimer.new(@missing_file_check_interval) do
323
339
  begin
324
340
  read_file_metadata do |filestat, linkstat, linktarget|
325
341
  handle_fstat(filestat, linkstat, linktarget)
326
342
  end
327
- timer.cancel
343
+ @missing_file_check_timer.cancel
328
344
  rescue Errno::ENOENT
329
345
  # The file disappeared. Wait for it to reappear.
330
346
  # This can happen if it was deleted or moved during log rotation.
@@ -39,7 +39,21 @@ class EventMachine::FileGlobWatch
39
39
  @watches = Hash.new
40
40
  @logger = Logger.new(STDOUT)
41
41
  @logger.level = ($DEBUG and Logger::DEBUG or Logger::WARN)
42
-
42
+ @interval = interval
43
+ start
44
+ end # def initialize
45
+
46
+ # This method may be called to stop watching
47
+ #
48
+ public
49
+ def stop
50
+ @find_files_interval.cancel if @find_files_interval
51
+ end
52
+
53
+ # This method may be called to start watching
54
+ #
55
+ public
56
+ def start
43
57
  # We periodically check here because it is easier than writing our own glob
44
58
  # parser (so we can smartly watch globs like /foo/*/bar*/*.log)
45
59
  #
@@ -48,12 +62,12 @@ class EventMachine::FileGlobWatch
48
62
  # files.
49
63
  EM.next_tick do
50
64
  find_files
51
- EM.add_periodic_timer(interval) do
65
+ @find_files_interval = EM.add_periodic_timer(@interval) do
52
66
  find_files
53
67
  end
54
68
  end # EM.next_tick
55
- end # def initialize
56
-
69
+ end
70
+
57
71
  # This method is called when a new file is found
58
72
  #
59
73
  # * path - the string path of the file found
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eventmachine-tail
3
3
  version: !ruby/object:Gem::Version
4
- hash: 3
4
+ hash: 1
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 6
9
- - 2
10
- version: 0.6.2
9
+ - 3
10
+ version: 0.6.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jordan Sissel
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-08-10 00:00:00 -07:00
18
+ date: 2011-08-29 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency