Skip to content

Commit

Permalink
Revert "Add logic to cater historic applications/statuses"
Browse files Browse the repository at this point in the history
  • Loading branch information
javier-npq authored Oct 23, 2023
1 parent edadc41 commit c942cd2
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 43 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/update_application_statuses.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Update Application Statuses
on:
schedule:
- cron: '0 */2 * * *'
- cron: '0 0 * * *'

jobs:
sweep:
Expand Down
33 changes: 5 additions & 28 deletions app/lib/services/ecf/ecf_application_synchronization.rb
Original file line number Diff line number Diff line change
@@ -1,50 +1,27 @@
module Services
module Ecf
class EcfApplicationSynchronization
PER_PAGE = 50
DEFAULT_LIMIT = 1000

def initialize(limit = DEFAULT_LIMIT)
@limit = limit
end

def call
process_batch_applications
uri = build_uri
request = build_http_get_request(uri)
response = send_http_request(uri, request)
handle_response(response)
rescue StandardError => e
Rails.logger.error "An error occurred during application synchronization: #{e.message}"
end

private

# Remove this code once all application statuses have been migrated.
def process_batch_applications
applications_to_sync.find_in_batches(batch_size: PER_PAGE) do |group|
batch_runner(group.pluck(:ecf_id))
end
end

def batch_runner(batch)
uri = build_uri
request = build_http_get_request(uri, batch)
response = send_http_request(uri, request)
handle_response(response)
end

def build_uri
URI.parse("#{ENV['ECF_APP_BASE_URL']}/api/v1/npq/application_synchronizations")
end

def build_http_get_request(uri, ecf_ids)
uri.query = "ecf_ids=#{ecf_ids.join(',')}"
def build_http_get_request(uri)
request = Net::HTTP::Get.new(uri)
request["Authorization"] = "Bearer #{ENV['ECF_APP_BEARER_TOKEN']}"
request
end

def applications_to_sync
Application.where(lead_provider_approval_status: nil).limit(@limit)
end

def send_http_request(uri, request)
Net::HTTP.start(uri.hostname, uri.port, use_ssl: use_ssl?, read_timeout: 30) do |http|
http.request(request)
Expand Down
14 changes: 0 additions & 14 deletions spec/lib/services/ecf/ecf_application_synchronization_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,6 @@

service.call
end

it "builds the correct URI with the query parameter" do
ecf_ids = SecureRandom.uuid
uri = URI.parse("https://ecf-app.gov.uk/api/v1/npq/application_synchronizations")
request = instance_double("Net::HTTP::Get")
http = instance_double("Net::HTTP")

allow(URI).to receive(:parse).with("https://ecf-app.gov.uk/api/v1/npq/application_synchronizations").and_return(uri)
allow(http).to receive(:request).with(request).and_return(success_response)

uri.query = "ecf_ids=#{ecf_ids}"

service.call
end
end

context "when an error occurs" do
Expand Down

0 comments on commit c942cd2

Please sign in to comment.