Skip to content

Commit

Permalink
add study sync related logs
Browse files Browse the repository at this point in the history
  • Loading branch information
akabishau committed Sep 12, 2024
1 parent a507804 commit 7b08706
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/services/ct_gov/api_client/v2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def fetch_studies(range: nil, nct_ids: nil, page_size: nil)
total_count = result["totalCount"] if result["totalCount"]
total_fetched += studies.size
Rails.logger.info("Dowloaded #{total_fetched} from #{total_count} studies")

puts "Dowloaded #{total_fetched} from #{total_count} studies"
# Yield each page of studies to the caller
yield studies

Expand Down
2 changes: 2 additions & 0 deletions app/services/ct_gov/study_sync_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def refresh_studies_from_db

def remove_studies(nct_ids)
Rails.logger.info("Removing #{nct_ids} studies from the database")
puts "Removing #{nct_ids} studies from the database"
StudyJsonRecord.where(nct_id: nct_ids, version: @api_client.version).delete_all
# remove study and related records
nct_ids.each do |nct_id|
Expand All @@ -58,6 +59,7 @@ def persist(studies)
)

Rails.logger.info("Imported #{study_records.size} StudyJsonRecords")
puts "Imported #{study_records.size} StudyJsonRecords"
end
end

Expand Down
3 changes: 2 additions & 1 deletion app/services/http_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ def setup_connection(base_url, timeout: 10, open_timeout: 5, retries: 3)
@connection = Faraday.new(url: base_url) do |f|
f.request :json # for post requests - not currently used
f.request :retry, retry_options # faraday-retry gem
f.response :logger, nil, { headers: false, bodies: false, errors: true }
# using Rails.logger for now
f.response :logger, Rails.logger, { headers: false, bodies: false, errors: true }
f.response :raise_error # 40x, 50x errors -> Faraday::ClientError, Faraday::ServerError
f.response :json # parse json response into body; fails with Faraday::ParsingError
f.adapter Faraday.default_adapter # keep for clarity
Expand Down

0 comments on commit 7b08706

Please sign in to comment.