Class: GroongaDelta::LocalDelta

Inherits:
Object
  • Object
show all
Defined in:
lib/groonga-delta/local-delta.rb

Defined Under Namespace

Classes: CommandProcessor

Instance Method Summary collapse

Constructor Details

#initialize(config, status) ⇒ LocalDelta

Returns a new instance of LocalDelta.



22
23
24
25
26
27
# File 'lib/groonga-delta/local-delta.rb', line 22

def initialize(config, status)
  @config = config
  @status = status
  @logger = @config.logger
  @delta_dir = @config.local.delta_dir
end

Instance Method Details

#applyObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/groonga-delta/local-delta.rb', line 29

def apply
  reader = LocalReader.new(@logger, @delta_dir)
  start_time = read_current_status(reader)
  current_time = Time.now.utc
  client_options = {
    url: @config.groonga.url,
    read_timeout: @config.groonga.read_timeout,
    backend: :synchronous,
  }
  Groonga::Client.open(client_options) do |client|
    processor = CommandProcessor.new(@config,
                                     client,
                                     target_commands: [],
                                     target_tables: [],
                                     target_columns: [])
    reader.each(start_time, current_time) do |target|
      target.apply(@logger, client, processor)
      @status.update("start_time" => [
                       target.timestamp.to_i,
                       target.timestamp.nsec,
                     ])
    end
  end
end