Class: Lab::Lims::Migrator::CouchDbMigratorApi

Inherits:
Api::CouchDbApi show all
Defined in:
app/services/lab/lims/migrator.rb

Overview

A Lab::Lims::Api object that supports crawling of a LIMS CouchDB instance.

Instance Attribute Summary

Attributes inherited from Api::CouchDbApi

#bum

Instance Method Summary collapse

Methods inherited from Api::CouchDbApi

#create_order, #update_order

Constructor Details

#initialize(*args, processes: 1, on_merge_processes: nil, **kwargs) ⇒ CouchDbMigratorApi

Returns a new instance of CouchDbMigratorApi.



64
65
66
67
68
69
# File 'app/services/lab/lims/migrator.rb', line 64

def initialize(*args, processes: 1, on_merge_processes: nil, **kwargs)
  super(*args, **kwargs)

  @processes = processes
  @on_merge_processes = on_merge_processes
end

Instance Method Details

#consume_orders(from: nil, **_kwargs) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'app/services/lab/lims/migrator.rb', line 71

def consume_orders(from: nil, **_kwargs)
  limit = 25_000

  loop do
    on_merge_processes = ->(_item, index, _result) { @on_merge_processes&.call(from + index) }
    processes = @processes > 1 ? @processes : 0

    orders = read_orders(from, limit)
    break if orders.empty?

    Parallel.each(orders, in_processes: processes, finish: on_merge_processes) do |row|
      next unless row['doc']['type']&.casecmp?('Order')

      User.current = Utils.lab_user
      yield OrderDTO.new(row['doc']), OpenStruct.new(last_seq: (from || 0) + limit, current_seq: from)
    end

    from += orders.size
  end
end