Module: Fairy::RomaPutInterface

Defined in:
lib/fairy/client/roma-put.rb

Constant Summary collapse

DEFAULT_SPLIT =
100

Instance Method Summary collapse

Instance Method Details

#roma_put(ap, base_key, split = DEFAULT_SPLIT, opts = {}) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/fairy/client/roma-put.rb', line 14

def roma_put(ap, base_key, split=DEFAULT_SPLIT, opts={})
  ap = [ap] if ap.kind_of?(String)

  @fairy.def_pool_variable(:__ROMA_PUT_ap, ap)
  @fairy.def_pool_variable(:__ROMA_PUT_base_key, base_key)
  @fairy.def_pool_variable(:__ROMA_PUT_split, split)

  if opts[:nice]
	@fairy.def_pool_variable(:__ROMA_PUT_nice, opts[:nice])
  else
	@fairy.def_pool_variable(:__ROMA_PUT_nice, 0)
  end

  seg_map(%{|i, block|
      system('renice '+@Pool.__ROMA_PUT_nice.to_s+' '+$$.to_s) unless @Pool.__ROMA_PUT_nice.zero?

      require 'roma/client/rclient'

      @roma = Roma::Client::RomaClient.new(@Pool.__ROMA_PUT_ap.dc_deep_copy)
      @base_key = @Pool.__ROMA_PUT_base_key + $$.to_s + '_' + __id__.to_s
      @split = @Pool.__ROMA_PUT_split

      buf = []
      cnt = 0
      put_cnt = 0
      i.each{|e|
        cnt += 1
        buf << e
        if (cnt % @split == 0)
          key = @base_key + ('%03d' % put_cnt)
          @roma[key] = buf.join(',')
          block.call(key)
          buf.clear
          put_cnt += 1
        end
      }
      if buf.size > 0
        key = @base_key + ('%03d' % put_cnt)
        @roma[key] = buf.join(',')
        block.call(key)
        buf.clear
      end
    })
end