Class: Lab::Lims::Api::MysqlApi
- Inherits:
-
Object
- Object
- Lab::Lims::Api::MysqlApi
- Defined in:
- app/services/lab/lims/api/mysql_api.rb
Class Method Summary collapse
Instance Method Summary collapse
- #consume_orders(from: nil, limit: 1000) ⇒ Object
-
#initialize(processes: 1, on_merge_processes: nil) ⇒ MysqlApi
constructor
A new instance of MysqlApi.
- #multiprocessed? ⇒ Boolean
- #parallel_map(items, on_merge: nil, &block) ⇒ Object
Constructor Details
#initialize(processes: 1, on_merge_processes: nil) ⇒ MysqlApi
Returns a new instance of MysqlApi.
18 19 20 21 22 |
# File 'app/services/lab/lims/api/mysql_api.rb', line 18 def initialize(processes: 1, on_merge_processes: nil) @processes = processes @on_merge_processes = on_merge_processes @mysql_connection_pool = {} end |
Class Method Details
Instance Method Details
#consume_orders(from: nil, limit: 1000) ⇒ Object
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 58 59 |
# File 'app/services/lab/lims/api/mysql_api.rb', line 28 def consume_orders(from: nil, limit: 1000) loop do specimens_to_process = specimens(from, limit) break if specimens_to_process.size.zero? processes = multiprocessed? ? @processes : 0 on_merge_processes = ->(_item, index, _result) { @on_merge_processes&.call(from + index) } Parallel.map(specimens_to_process, in_processes: processes, finish: on_merge_processes) do |specimen| User.current ||= Utils.lab_user tests = specimen_tests(specimen['specimen_id']) results = tests.each_with_object({}) do |test, object| object[test['test_name']] = test_results(test['test_id']) end dto = make_order_dto( specimen: specimen, patient: specimen_patient(specimen['specimen_id']), test_results: results, specimen_status_trail: specimen_status_trail(specimen['specimen_id']), test_status_trail: tests.each_with_object({}) do |test, trails| trails[test['test_name']] = test_status_trail(test['test_id']) end ) yield dto, OpenStruct.new(last_seq: from) end from += limit end end |
#multiprocessed? ⇒ Boolean
24 25 26 |
# File 'app/services/lab/lims/api/mysql_api.rb', line 24 def multiprocessed? @processes > 1 end |
#parallel_map(items, on_merge: nil, &block) ⇒ Object
61 |
# File 'app/services/lab/lims/api/mysql_api.rb', line 61 def parallel_map(items, on_merge: nil, &block); end |