Class: Gizzard::GizzmoService

Inherits:
ThriftClient::Simple::ThriftService show all
Defined in:
lib/gizzard/thrift.rb

Direct Known Subclasses

JobInjector, Manager

Instance Method Summary collapse

Methods inherited from ThriftClient::Simple::ThriftService

_arg_structs, thrift_method

Constructor Details

#initialize(host, port, log_path, framed, dry_run = false) ⇒ GizzmoService

Returns a new instance of GizzmoService.



121
122
123
124
125
126
127
128
129
# File 'lib/gizzard/thrift.rb', line 121

def initialize(host, port, log_path, framed, dry_run = false)
  super(host, port, framed)
  @dry = dry_run
  begin
    @log = File.open(log_path, "a")
  rescue
    STDERR.puts "Error opening log file at #{log_path}.  Continuing..."
  end
end

Instance Method Details

#_proxy(method_name, *args) ⇒ Object



131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/gizzard/thrift.rb', line 131

def _proxy(method_name, *args)
  cls = self.class.ancestors.find { |cls| cls.respond_to?(:_arg_structs) and cls._arg_structs[method_name.to_sym] }
  arg_class, rv_class = cls._arg_structs[method_name.to_sym]

  # Writing methods return void. Methods should never both read and write. If this assumption
  # is violated in the future, dry-run will fail!!
  is_writing_method = rv_class._fields.first.type == ThriftClient::Simple::VOID
  if @dry && is_writing_method
    puts "Skipped writing: #{printable(method_name, args)}"
  else
    @log.puts printable(method_name, args, true)
    super(method_name, *args)
  end
end

#printable(method_name, args, timestamp = false) ⇒ Object



146
147
148
149
# File 'lib/gizzard/thrift.rb', line 146

def printable(method_name, args, timestamp = false)
  ts = timestamp ? "#{Time.now}\t" : ""
  "#{ts}#{method_name}(#{args.map{|a| a.inspect}.join(', ')})"
end