Class: Maatkit::FifoSplit

Inherits:
Object
  • Object
show all
Defined in:
lib/maatkit-ruby/mk-fifo-split.rb

Overview

Split files and pipe lines to a fifo without really splitting.

Maatkit::FifoSplit.new( array, str, array)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeFifoSplit

Returns a new FifoSplit Object



73
74
# File 'lib/maatkit-ruby/mk-fifo-split.rb', line 73

def initialize()
end

Instance Attribute Details

#configObject

type: Array Read this comma-separated list of config files; if specified, this must be the first option on the command line.



19
20
21
# File 'lib/maatkit-ruby/mk-fifo-split.rb', line 19

def config
  @config
end

#fifoObject

type: string; default: /tmp/mk-fifo-split The name of the fifo from which the lines can be read.



24
25
26
# File 'lib/maatkit-ruby/mk-fifo-split.rb', line 24

def fifo
  @fifo
end

#forceObject

Remove the fifo if it exists already, then create it again.



28
29
30
# File 'lib/maatkit-ruby/mk-fifo-split.rb', line 28

def force
  @force
end

#helpObject

Show help and exit.



32
33
34
# File 'lib/maatkit-ruby/mk-fifo-split.rb', line 32

def help
  @help
end

#linesObject

type: int; default: 1000 The number of lines to read in each chunk.



37
38
39
# File 'lib/maatkit-ruby/mk-fifo-split.rb', line 37

def lines
  @lines
end

#offsetObject

type: int; default: 0 Begin at the Nth line. If the argument is 0, all lines are printed to the fifo. If 1, then beginning at the first line, lines are printed (exactly the same as 0). If 2, the first line is skipped, and the 2nd and subsequent lines are printed to the fifo.



44
45
46
# File 'lib/maatkit-ruby/mk-fifo-split.rb', line 44

def offset
  @offset
end

#path_to_mk_fifo_splitObject

Sets the executable path, otherwise the environment path will be used.



68
69
70
# File 'lib/maatkit-ruby/mk-fifo-split.rb', line 68

def path_to_mk_fifo_split
  @path_to_mk_fifo_split
end

#pidObject

type: string Create the given PID file. The file contains the process ID of the script. The PID file is removed when the script exits. Before starting, the script checks if the PID file already exists. If it does not, then the script creates and writes its own PID to it. If it does, then the script checks the following: if the file contains a PID and a process is running with that PID, then the script dies; or, if there is no process running with that PID, then the script overwrites the file with its own PID and starts; else, if the file contains no PID, then the script dies.



54
55
56
# File 'lib/maatkit-ruby/mk-fifo-split.rb', line 54

def pid
  @pid
end

#statisticsObject

Print out statistics between chunks. The statistics are the number of chunks, the number of lines, elapsed time, and lines per second overall and during the last chunk.



59
60
61
# File 'lib/maatkit-ruby/mk-fifo-split.rb', line 59

def statistics
  @statistics
end

#versionObject

Show version and exit.



63
64
65
# File 'lib/maatkit-ruby/mk-fifo-split.rb', line 63

def version
  @version
end

Instance Method Details

#start(options = nil) ⇒ Object

Execute the command



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/maatkit-ruby/mk-fifo-split.rb', line 79

def start(options = nil)
  tmp = Tempfile.new('tmp')
  command = option_string() + options.to_s + " 2> " + tmp.path
  success = system(command)
  if success
    begin
      while (line = tmp.readline)
        line.chomp
        selected_string = line
      end
    rescue EOFError
      tmp.close
    end
    return selected_string
  else
    tmp.close!
    return success
  end
end