Class: Resque::Pool::Dynamic::Logfile
- Inherits:
-
IO::Tail::Logfile
- Object
- IO::Tail::Logfile
- Resque::Pool::Dynamic::Logfile
- Defined in:
- lib/resque/pool/dynamic/logfile.rb
Overview
Slightly customized tailable file class
Instance Attribute Summary collapse
-
#pid ⇒ Integer, NilClass
PID of process that writes the log file.
Class Method Summary collapse
Instance Method Summary collapse
-
#alive? ⇒ Boolean
True if child process is alive.
-
#restat ⇒ Object
Make sure to return on EOF if process is dead.
-
#tail(n = nil) {|ln| ... } ⇒ Object
Show last n lines of the file, or follow the file.
-
#tail_to_eof ⇒ Object
Print contents of the file until current end of file.
-
#tail_until(rx) ⇒ Object
Follow the file until a line matches regexp.
Instance Attribute Details
#pid ⇒ Integer, NilClass
PID of process that writes the log file
32 33 34 |
# File 'lib/resque/pool/dynamic/logfile.rb', line 32 def pid @pid end |
Class Method Details
.open(filename, opts = {}, &block) ⇒ Object
34 35 36 37 |
# File 'lib/resque/pool/dynamic/logfile.rb', line 34 def self.open(filename, opts = {}, &block) raise "Need :pid" unless opts.has_key? :pid super end |
Instance Method Details
#alive? ⇒ Boolean
True if child process is alive
40 41 42 |
# File 'lib/resque/pool/dynamic/logfile.rb', line 40 def alive? Process.getpgid(pid) rescue nil end |
#restat ⇒ Object
Make sure to return on EOF if process is dead
45 46 47 48 |
# File 'lib/resque/pool/dynamic/logfile.rb', line 45 def restat self.return_if_eof = true unless alive? super end |
#tail(n = nil) {|ln| ... } ⇒ Object
Show last n lines of the file, or follow the file
55 56 57 58 59 60 61 62 |
# File 'lib/resque/pool/dynamic/logfile.rb', line 55 def tail(n = nil, &block) super(n) do |ln| $stderr.puts ln block.call(ln) if block end rescue Interrupt => e nil end |
#tail_to_eof ⇒ Object
Print contents of the file until current end of file
74 75 76 77 78 79 |
# File 'lib/resque/pool/dynamic/logfile.rb', line 74 def tail_to_eof orig_return_if_eof, return_if_eof = return_if_eof, true tail ensure return_if_eof = orig_return_if_eof end |
#tail_until(rx) ⇒ Object
Follow the file until a line matches regexp
66 67 68 69 70 |
# File 'lib/resque/pool/dynamic/logfile.rb', line 66 def tail_until(rx) self.tail do |ln| raise IO::Tail::ReturnException if ln =~ rx end end |