Class: Facilities::DentalServiceReloadJob
- Inherits:
-
Object
- Object
- Facilities::DentalServiceReloadJob
show all
- Includes:
- SentryLogging, Sidekiq::Job
- Defined in:
- app/sidekiq/facilities/dental_service_reload_job.rb
Instance Method Summary
collapse
#log_exception_to_sentry, #log_message_to_sentry, #non_nil_hash?, #normalize_level, #rails_logger
Instance Method Details
#fetch_dental_service_data(file) ⇒ Object
15
16
17
18
19
|
# File 'app/sidekiq/facilities/dental_service_reload_job.rb', line 15
def fetch_dental_service_data(file)
CSV.read(file, headers: true)
rescue => e
raise DentalServiceError, "Failed to read CSV file: #{file} - caused by: #{e.cause}"
end
|
#parse_dental_service_data(records) ⇒ Object
35
36
37
|
# File 'app/sidekiq/facilities/dental_service_reload_job.rb', line 35
def parse_dental_service_data(records)
records.map { |r| r['unique_id'] }
end
|
49
50
51
|
# File 'app/sidekiq/facilities/dental_service_reload_job.rb', line 49
def perform
update_dental_service_data
end
|
#remove_invalid_keys(facility_keys) ⇒ Object
#update_cache(facilities) ⇒ Object
21
22
23
24
25
26
27
28
|
# File 'app/sidekiq/facilities/dental_service_reload_job.rb', line 21
def update_cache(facilities)
facilities.each do |facility_id|
attrs = { station_number: facility_id,
local_updated: Time.now.utc.iso8601 }
dental_record = FacilityDentalService.find_or_build(facility_id)
dental_record.update(attrs)
end
end
|
#update_dental_service_data ⇒ Object
39
40
41
42
43
44
45
46
47
|
# File 'app/sidekiq/facilities/dental_service_reload_job.rb', line 39
def update_dental_service_data
dental_file = Rails.root.join('lib', 'facilities', 'dental_service_data', 'dental_services.csv')
records = fetch_dental_service_data(dental_file)
facilities = parse_dental_service_data(records)
update_cache(facilities)
remove_invalid_keys(facilities)
rescue Facilities::DentalServiceError => e
log_exception_to_sentry(e)
end
|