Class: KMExport::Reimporter
- Inherits:
-
Object
- Object
- KMExport::Reimporter
- Defined in:
- lib/reimporter.rb
Instance Method Summary collapse
Instance Method Details
#send_line_to_KM(line) ⇒ Object
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/reimporter.rb', line 52 def send_line_to_KM(line) identity = line.delete("_p") second_identity = line.delete("_p2") event = line.delete("_n") line["_d"] = 1 KMTS.alias(identity,second_identity) if second_identity KMTS.record(identity,event,line) if event KMTS.set(identity,line) unless event || second_identity end |
#send_to_KM(json, key, offset) ⇒ Object
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 |
# File 'lib/reimporter.rb', line 26 def send_to_KM(json, key, offset) pool = 10 threads = [] queue = JSONQueue.new({file: json, counter: offset}) queue.offset(offset) queue.add_to_queue pool.times do threads << Thread.new do KMTS.init(key, :use_cron => false, :to_stderr => true) until queue.empty? queue.add_to_queue if queue.length < 50 work_unit = queue.pop(true) rescue nil send_line_to_KM(work_unit) end end end threads.each { |t| t.join } STDOUT.print('Reimportation process completed.') end |