Class: Lab::UpdatePatientOrdersJob
- Inherits:
-
ApplicationJob
- Object
- ActiveJob::Base
- ApplicationJob
- Lab::UpdatePatientOrdersJob
- Defined in:
- app/jobs/lab/update_patient_orders_job.rb
Overview
Fetches updates on a patient’s orders from external sources.
Instance Method Summary collapse
Instance Method Details
#perform(patient_id) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'app/jobs/lab/update_patient_orders_job.rb', line 9 def perform(patient_id) Rails.logger.info('Initialising LIMS REST API...') User.current = Lab::Lims::Utils.lab_user Location.current = Location.find_by_name('ART clinic') lockfile = Rails.root.join('tmp', "update-patient-orders-#{patient_id}.lock") done = File.open(lockfile, File::RDWR | File::CREAT) do |lock| unless lock.flock(File::LOCK_NB | File::LOCK_EX) Rails.logger.info('Another update patient job is already running...') break false end worker = Lab::Lims::PullWorker.new(Lab::Lims::ApiFactory.create_api) worker.pull_orders(patient_id: patient_id) true end File.unlink(lockfile) if done end |