Class: Lab::Lims::AcknowledgementWorker

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
app/services/lab/lims/acknowledgement_worker.rb

Overview

This class is responsible for handling the acknowledgement of lab orders

Constant Summary collapse

SECONDS_TO_WAIT_FOR_ORDERS =
30

Constants included from Utils

Utils::LIMS_LOG_PATH, Utils::TEST_NAME_MAPPINGS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils

find_concept_by_name, lab_user, #logger, parse_date, structify, translate_test_name

Constructor Details

#initialize(lims_api) ⇒ AcknowledgementWorker

Returns a new instance of AcknowledgementWorker.



13
14
15
# File 'app/services/lab/lims/acknowledgement_worker.rb', line 13

def initialize(lims_api)
  @lims_api = lims_api
end

Instance Attribute Details

#lims_apiObject (readonly)

Returns the value of attribute lims_api.



7
8
9
# File 'app/services/lab/lims/acknowledgement_worker.rb', line 7

def lims_api
  @lims_api
end

Instance Method Details

#push_acknowledgement(batch_size: 1000, wait: false) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/services/lab/lims/acknowledgement_worker.rb', line 17

def push_acknowledgement(batch_size: 1000, wait: false)
  loop do
    logger.info('Looking for new acknowledgements to push to LIMS...')
    acknowledgements = Lab::AcknowledgementService.acknowledgements_pending_sync(batch_size).all

    logger.debug("Found #{acknowledgements.size} acknowledgements...")
    acknowledgements.each do |acknowledgement|
      Lab::AcknowledgementService.push_acknowledgement(acknowledgement, @lims_api)
    rescue GatewayError => e
      logger.error("Failed to push acknowledgement ##{acknowledgement.order_id}: #{e.class} - #{e.message}")
    end

    break unless wait

    logger.info('Waiting for acknowledgements...')
    sleep(Lab::Lims::Config.updates_poll_frequency)
  end
end