generated from DFE-Digital/govuk-rails-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #819 from DFE-Digital/CPDNPQ-1188-background-job-t…
…o-update-status-fields CPDNPQ-1188 Create a task to update status fields in the NPQ
- Loading branch information
Showing
44 changed files
with
341 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
name: Update Application Statuses | ||
on: | ||
schedule: | ||
- cron: '0 0 * * *' | ||
|
||
jobs: | ||
sweep: | ||
name: Update Application Statuses | ||
|
||
runs-on: ubuntu-20.04 | ||
steps: | ||
- name: Install CloudFoundry CLI | ||
shell: bash | ||
run: | | ||
wget -q -O - https://packages.cloudfoundry.org/debian/cli.cloudfoundry.org.key | sudo apt-key add - | ||
echo "deb https://packages.cloudfoundry.org/debian stable main" | sudo tee /etc/apt/sources.list.d/cloudfoundry-cli.list | ||
sudo apt-get update | ||
sudo apt-get install cf7-cli | ||
- name: Update Application Statuses for dev | ||
shell: bash | ||
env: | ||
PAAS_ORGANISATION: dfe | ||
# This is a shared PAAS space | ||
PAAS_SPACE: earlycareers-framework-dev | ||
ENV_STUB: dev | ||
APP_NAME: npq-registration | ||
CF_USERNAME: ${{ secrets.GOVPAAS_DEV_USERNAME }} | ||
CF_PASSWORD: ${{ secrets.GOVPAAS_DEV_PASSWORD }} | ||
run: | | ||
cf api https://api.london.cloud.service.gov.uk | ||
cf auth | ||
cf target -o "${{ env.PAAS_ORGANISATION }}" -s "${{ env.PAAS_SPACE }}" | ||
cf run-task "${{ env.APP_NAME }}"-"${{ env.ENV_STUB }}" --command "cd /app && /usr/local/bundle/bin/bundle exec rails runner 'ApplicationSynchronizationJob.perform_later'" --process worker --name update_application_statuses | ||
- name: Update Application Statuses for staging | ||
shell: bash | ||
env: | ||
PAAS_ORGANISATION: dfe | ||
# This is a shared PAAS space | ||
PAAS_SPACE: early-careers-framework-staging | ||
ENV_STUB: staging | ||
APP_NAME: npq-registration | ||
CF_USERNAME: ${{ secrets.GOVPAAS_STAG_USERNAME }} | ||
CF_PASSWORD: ${{ secrets.GOVPAAS_STAG_PASSWORD }} | ||
run: | | ||
cf api https://api.london.cloud.service.gov.uk | ||
cf auth | ||
cf target -o "${{ env.PAAS_ORGANISATION }}" -s "${{ env.PAAS_SPACE }}" | ||
cf run-task "${{ env.APP_NAME }}"-"${{ env.ENV_STUB }}" --command "cd /app && /usr/local/bundle/bin/bundle exec rails runner 'ApplicationSynchronizationJob.perform_later'" --process worker --name update_application_statuses | ||
- name: Update Application Statuses for sandbox | ||
shell: bash | ||
env: | ||
PAAS_ORGANISATION: dfe | ||
# This is a shared PAAS space | ||
PAAS_SPACE: early-careers-framework-sandbox | ||
ENV_STUB: sandbox | ||
APP_NAME: npq-registration | ||
CF_USERNAME: ${{ secrets.GOVPAAS_STAG_USERNAME }} | ||
CF_PASSWORD: ${{ secrets.GOVPAAS_STAG_PASSWORD }} | ||
run: | | ||
cf api https://api.london.cloud.service.gov.uk | ||
cf auth | ||
cf target -o "${{ env.PAAS_ORGANISATION }}" -s "${{ env.PAAS_SPACE }}" | ||
cf run-task "${{ env.APP_NAME }}"-"${{ env.ENV_STUB }}" --command "cd /app && /usr/local/bundle/bin/bundle exec rails runner 'ApplicationSynchronizationJob.perform_later'" --process worker --name update_application_statuses | ||
- name: Update Application Statuses for prod | ||
shell: bash | ||
env: | ||
PAAS_ORGANISATION: dfe | ||
# This is a shared PAAS space | ||
PAAS_SPACE: early-careers-framework-prod | ||
ENV_STUB: prod | ||
APP_NAME: npq-registration | ||
CF_USERNAME: ${{ secrets.GOVPAAS_PROD_USERNAME }} | ||
CF_PASSWORD: ${{ secrets.GOVPAAS_PROD_PASSWORD }} | ||
run: | | ||
cf api https://api.london.cloud.service.gov.uk | ||
cf auth | ||
cf target -o "${{ env.PAAS_ORGANISATION }}" -s "${{ env.PAAS_SPACE }}" | ||
cf run-task "${{ env.APP_NAME }}"-"${{ env.ENV_STUB }}" --command "cd /app && /usr/local/bundle/bin/bundle exec rails runner 'ApplicationSynchronizationJob.perform_later'" --process worker --name update_application_statuses |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class ApplicationSynchronizationJob < ApplicationJob | ||
queue_as :default | ||
def perform | ||
Services::Ecf::EcfApplicationSynchronization.new.call | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
module Services | ||
module Ecf | ||
class EcfApplicationSynchronization | ||
def call | ||
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 | ||
|
||
def build_uri | ||
URI.parse("#{ENV['ECF_APP_BASE_URL']}/api/v1/npq/application_synchronizations") | ||
end | ||
|
||
def build_http_get_request(uri) | ||
request = Net::HTTP::Get.new(uri) | ||
request["Authorization"] = "Bearer #{ENV['ECF_APP_BEARER_TOKEN']}" | ||
request | ||
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) | ||
end | ||
end | ||
|
||
def handle_response(response) | ||
if response.is_a?(Net::HTTPSuccess) | ||
data = response_data(response) | ||
data.each do |record| | ||
id = record.id | ||
lead_provider_approval_status = record.lead_provider_approval_status | ||
participant_outcome_state = record.participant_outcome_state | ||
|
||
application = Application.find_by!(ecf_id: id) | ||
application.update!(lead_provider_approval_status:, participant_outcome_state:) | ||
end | ||
else | ||
raise "Failed to update application: #{response.message}" | ||
end | ||
end | ||
|
||
def response_data(response) | ||
data = JSON.parse(response.body)["data"] | ||
array = [] | ||
data.each do |record| | ||
array << OpenStruct.new( | ||
id: record["attributes"]["id"], | ||
lead_provider_approval_status: record["attributes"]["lead_provider_approval_status"], | ||
participant_outcome_state: record["attributes"]["participant_outcome_state"], | ||
) | ||
end | ||
|
||
array | ||
end | ||
|
||
def use_ssl? | ||
build_uri.scheme == "https" | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ | |
{ | ||
key: { text: "Provider" }, | ||
value: { text: application.lead_provider.name }, | ||
} | ||
}, | ||
]) | ||
end %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<%= govuk_summary_card(title: "Provider details") do |card| | ||
|
||
card.with_summary_list(rows: [ | ||
{ | ||
key: { text: "Provider" }, | ||
value: { text: application.lead_provider.name } | ||
}, | ||
{ | ||
key: { text: "Provider Application" }, | ||
value: { text: application.participant_outcome_state ? application.participant_outcome_state&.capitalize : application.lead_provider_approval_status&.capitalize }, | ||
}, | ||
]) | ||
end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require File.expand_path(File.join(File.dirname(__FILE__), "..", "config", "environment")) | ||
|
||
every 1.day, at: "00:00" do | ||
runner "ApplicationSynchronizationJob.perform_later", environment: Rails.env | ||
end |
6 changes: 6 additions & 0 deletions
6
db/migrate/20230619162920_add_lead_provider_approval_status_to_applications.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class AddLeadProviderApprovalStatusToApplications < ActiveRecord::Migration[6.1] | ||
def change | ||
add_column :applications, :lead_provider_approval_status, :text | ||
add_column :applications, :participant_outcome_state, :text | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.