Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/APPEALS-57706: Establishment of a Prioritized National Hearing Queue #23416

Draft
wants to merge 40 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
e12a808
Install oracle_fdw extension in pg local
ThorntonMatthew Sep 23, 2024
62acf42
Add scenic gem
ThorntonMatthew Sep 23, 2024
4dbf662
Update Dockerfile to install ZScaler root cert
ThorntonMatthew Sep 23, 2024
6e456d2
Add migration
ThorntonMatthew Sep 23, 2024
53a6513
Add blank migration so I can switch branches
ThorntonMatthew Sep 23, 2024
65b8783
Add ISSUES FT
ThorntonMatthew Sep 23, 2024
0d68d31
Add db creation to init script
ThorntonMatthew Sep 24, 2024
2ea60fb
Check in in-flight changes
ThorntonMatthew Sep 25, 2024
bb992b9
Ignore zip file
ThorntonMatthew Sep 25, 2024
2794cd9
Merge branch 'master' into prototype/nhq-generation
ThorntonMatthew Sep 25, 2024
ec942f8
Adjust dockerfile to allow for docker network access to postgres service
ThorntonMatthew Oct 8, 2024
bc7adbe
Rename migration files
ThorntonMatthew Oct 8, 2024
f2e11e5
APPEALS-59236: Installing scenic gem (#23107)
noahhansen-gov Oct 8, 2024
e9e645d
Add platform to m1 docker-compose
ThorntonMatthew Oct 8, 2024
ca47e80
Add network_mode to postgres service
ThorntonMatthew Oct 8, 2024
89070e9
Use special DNS host address
ThorntonMatthew Oct 9, 2024
d64aed0
Merge branch 'master' into prototype/nhq-generation
ThorntonMatthew Oct 9, 2024
39c79fc
Merge branch 'master' into prototype/nhq-generation
ThorntonMatthew Oct 10, 2024
141e25d
Merge branch 'master' into feature/APPEALS-57706
ThorntonMatthew Oct 10, 2024
d168ed5
APPEALS-59219 Updating oracle_fdw setup script (#23181)
prernadevbah Oct 17, 2024
3f47ba3
APPEALS-59238: Create a national_hearing_queue_entries Materialized V…
noahhansen-gov Oct 17, 2024
f1ab788
Pull in infrastructure pieces from prototype branch
ThorntonMatthew Oct 18, 2024
58f3ce4
APPEALS-59235 Add foreign tables for VACOLS (#23297)
prernadevbah Oct 21, 2024
4f50796
Merge branch 'master' into feature/APPEALS-57706
ThorntonMatthew Oct 22, 2024
2436aae
APPEALS-59239: Update of the national_hearing_queue_entries View Defi…
ThorntonMatthew Oct 28, 2024
7f2b194
Merge branch 'master' into feature/APPEALS-57706
ThorntonMatthew Oct 31, 2024
f2daec4
Min/APPEALS-59243 (#23391)
minhazur9 Oct 31, 2024
9101ade
prernadev/APPEALS-59241: Add AOD Field to national_hearing_queue_entr…
ThorntonMatthew Nov 1, 2024
81a5281
Allow for concurrent refreshes of the NHQ view
ThorntonMatthew Nov 2, 2024
b2f6f59
Remove the vbms_ext_claim table
ThorntonMatthew Nov 2, 2024
62901e5
Fix tests to respect DST:
ThorntonMatthew Nov 4, 2024
dab1f70
Merge branch 'dev-supporting/APPEALS-63886' into feature/APPEALS-57706
ThorntonMatthew Nov 6, 2024
365acab
Min/APPEALS-59455 (#23421)
minhazur9 Nov 7, 2024
bd45288
APPEALS-59446: Creation of an Asynchronous Job That Will Refresh the …
noahhansen-gov Nov 8, 2024
9bce2b8
MattT/APPEALS-64451 (#23480)
ThorntonMatthew Nov 13, 2024
55036e4
Min/APPEALS-63928 (#23478)
minhazur9 Nov 13, 2024
3f1c45b
MattT/APPEALS-64534: Create PL/pgSQL Function to Return a Table of f_…
ThorntonMatthew Nov 14, 2024
8c87942
Merge remote-tracking branch 'origin/main' into feature/APPEALS-57706
ThorntonMatthew Nov 15, 2024
ede7786
Caching State and Country of Residence for Veterans with Pending Hear…
prernadevbah Nov 15, 2024
547977b
MattT/APPEALS-64593: Create PL/pgSQL Function to Return bfcorkeys of …
ThorntonMatthew Nov 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 37 additions & 20 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,16 @@ jobs:
timeout-minutes: 45
services:
postgres:
image: postgres:14.8
image: 065403089830.dkr.ecr.us-gov-west-1.amazonaws.com/caseflow-postgres-ci:14.9
credentials:
username: AWS
password: ${{ secrets.VAEC_ECR_PASSWORD }}
env:
POSTGRES_USER: root
POSTGRES_PASSWORD: password
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: caseflow_certification_test

ports:
- 5432:5432

options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5

redis:
Expand Down Expand Up @@ -74,8 +75,8 @@ jobs:
BUNDLE_PATH: vendor/bundle
COVERAGE_DIR: /home/circleci/coverage-${{matrix.ci_node_index}} #circleci is the USER
POSTGRES_HOST: postgres
POSTGRES_USER: root
POSTGRES_PASSWORD: password
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
KNAPSACK_PRO_RSPEC_SPLIT_BY_TEST_EXAMPLES: true
KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC: ${{ secrets.KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC }}
KNAPSACK_PRO_CI_NODE_TOTAL: ${{ matrix.ci_node_total }}
Expand Down Expand Up @@ -194,31 +195,47 @@ jobs:
&& sudo tar -C /usr/local/bin -xzvf dockerize-linux-amd64-${DOCKERIZE_VERSION}.tar.gz \
&& rm dockerize-linux-amd64-${DOCKERIZE_VERSION}.tar.gz

- name: "Wait for database"
- name: Wait for the Postgres Database to Boot
run: dockerize -wait tcp://postgres:5432 -timeout 1m

- name: "Wait for localstack"
run: dockerize -wait tcp://localstack:4566 -timeout 30s

- name: "Wait for FACOLS"
run: ./ci-bin/capture-log "bundle exec rake local:vacols:wait_for_connection"
run: bundle exec rake local:vacols:wait_for_connection

- name: "Install psql"
run: sudo apt-get install -y postgresql-client

- name: Database setup
- name: Postgres Database Creation
run: |
./ci-bin/capture-log "bundle exec rake db:create:etl db:schema:load:etl"
./ci-bin/capture-log "bundle exec rake db:create:primary db:schema:load:primary"
./ci-bin/capture-log "make -f Makefile.example external-db-create"
bundle exec rake db:create:etl
bundle exec rake db:create:primary
# added line to create external table(s) that are needed for tests

- name: Install Postgres Extensions
run: psql -h postgres -U postgres -d caseflow_certification_test -a -f docker-bin/pg/setup_extensions_test.sql

# We don't want to seed DBs here because DatabaseCleaner just truncates it anyway. The setup_vacols
# rake task needs to be run because it adds data to two tables that are ignored by DBCleaner
- name: Seed databases
- name: Seed the VACOLS database
run: bundle exec rake spec:setup_vacols

- name: Set Up Foreign Tables
run: psql -h postgres -U postgres -d caseflow_certification_test -a -f local/sql/create_foreign_tables_for_vacols_test.sql

- name: Set up Custom Types
run: psql -h postgres -U postgres -d caseflow_certification_test -a -f local/sql/create_custom_types.sql

- name: Postgres Database Schema Setup
run: |
./ci-bin/capture-log "bundle exec rake spec:setup_vacols"
bundle exec rake db:schema:load:etl
bundle exec rake db:schema:load:primary
make -f Makefile.example external-db-create
# added line to create external table(s) that are needed for tests

- name: "Wait for localstack"
run: dockerize -wait tcp://localstack:4566 -timeout 30s

- name: Assets Precompile
run: |
./ci-bin/capture-log "bundle exec rake assets:precompile"
run: bundle exec rake assets:precompile

# Changing the user and permissions as Chrome/Chromedriver can't run as root
- name: RSpec via knapsack_pro Queue Mode
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,6 @@ docs/schema/*
!.vscode/settings.json
!.vscode/launch.json
!.vscode/tasks.json

docker-bin/pg/*.zip
docker-bin/pg/*.crt
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ gem "countries"
gem "dry-schema", "~> 1.4"
gem "fast_jsonapi"
gem "fuzzy_match"
gem "fx", "~> 0.8.0"
gem "govdelivery-tms", require: "govdelivery/tms/mail/delivery_method"
gem "holidays", "~> 6.4"
gem "icalendar"
Expand Down Expand Up @@ -88,6 +89,7 @@ gem "rtf"
gem "ruby_claim_evidence_api", git: "https://github.com/department-of-veterans-affairs/ruby_claim_evidence_api.git", ref: "fed623802afe7303f4b8b5fe27cff0e903699873"
# Use SCSS for stylesheets
gem "sass-rails", "~> 5.0"
gem "scenic"
# Error reporting to Sentry
gem "sentry-raven"
gem "shoryuken", "3.1.11"
Expand Down
8 changes: 8 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1602,6 +1602,9 @@ GEM
foreman (0.87.2)
formatador (0.2.5)
fuzzy_match (2.1.0)
fx (0.8.0)
activerecord (>= 6.0.0)
railties (>= 6.0.0)
get_process_mem (0.2.7)
ffi (~> 1.0)
git (1.13.2)
Expand Down Expand Up @@ -2029,6 +2032,9 @@ GEM
sawyer (0.8.2)
addressable (>= 2.3.5)
faraday (> 0.8, < 2.0)
scenic (1.8.0)
activerecord (>= 4.0.0)
railties (>= 4.0.0)
scss_lint (0.60.0)
sass (~> 3.5, >= 3.5.5)
selenium-webdriver (4.9.0)
Expand Down Expand Up @@ -2171,6 +2177,7 @@ DEPENDENCIES
fasterer
foreman
fuzzy_match
fx (~> 0.8.0)
govdelivery-tms
guard-rspec
holidays (~> 6.4)
Expand Down Expand Up @@ -2241,6 +2248,7 @@ DEPENDENCIES
ruby-prof (~> 1.4)
ruby_claim_evidence_api!
sass-rails (~> 5.0)
scenic
scss_lint
sentry-raven
shoryuken (= 3.1.11)
Expand Down
9 changes: 3 additions & 6 deletions PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<!-- Change JIRA-12345 to reflect the URL of the Jira item this PR is associated with -->
Resolves [Jira Issue Title](https://jira.devops.va.gov/browse/JIRA-12345)

> [!CAUTION]
> **Do not include any screenshots within this PR description.**

# Description
Please explain the changes you made here.

Expand All @@ -14,12 +17,6 @@ Please explain the changes you made here.
- [ ] For feature branches merging into main: Was this deployed to UAT?

# Frontend
## User Facing Changes
- [ ] Screenshots of UI changes added to PR & Original Issue

BEFORE|AFTER
---|---

## Storybook Story
*For Frontend (Presentation) Components*
* [ ] Add a [Storybook](https://github.com/department-of-veterans-affairs/caseflow/wiki/Documenting-React-Components-with-Storybook) file alongside the component file (e.g. create `MyComponent.stories.js` alongside `MyComponent.jsx`)
Expand Down
56 changes: 56 additions & 0 deletions app/jobs/check_veteran_residence_location_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# frozen_string_literal: true

class CheckVeteranResidenceLocationJob < CaseflowJob
RESIDENCE_LOCATION_PROCESS_LIMIT = ENV.fetch("RESIDENCE_LOCATION_BATCH_SIZE", 2500).to_i
VET_UPDATE_BATCH_PROCESS_LIMIT = ENV.fetch("VET_UPDATE_BATCH_SIZE", 100).to_i

def perform
user = User.system_user
ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
# Setting up parallel threads to retrieve and process all the veteran residence details
vet_updates = Parallel.map(retrieve_veterans, in_threads: 4) do |veteran|
begin
# Make sure the current user is set
RequestStore[:current_user] = user
{ id: veteran.id, state_of_residence: veteran.address.state,
country_of_residence: veteran.address.country,
residence_location_last_checked_at: Time.zone.now }
rescue StandardError => error
log_error(error)
end
end

batch_update_veterans(vet_updates.filter { !!_1 }) unless vet_updates.filter { !!_1 }.empty?
end
end

private

def retrieve_veterans
begin
# Retrieves all the Veteran entries where there is no residence information,
# or where the residence information was last checked over a week ago
check_veteran_residence = Veteran.where(state_of_residence: nil, country_of_residence: nil).or(
Veteran.where("residence_location_last_checked_at <= ?", 1.week.ago)
).limit(RESIDENCE_LOCATION_PROCESS_LIMIT)

check_veteran_residence
rescue StandardError => error
log_error(error)
raise error
end
end

def batch_update_veterans(vet_updates)
begin
# Update the Veteran table in batches
vet_updates.in_groups_of(VET_UPDATE_BATCH_PROCESS_LIMIT, false) do |batch|
updated_vet_hash = batch.index_by { |vet| vet[:id] }
Veteran.update(updated_vet_hash.keys, updated_vet_hash.values)
end
rescue StandardError => error
log_error(error)
raise error
end
end
end
43 changes: 43 additions & 0 deletions app/jobs/national_hearing_queue_entry_refresh_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# frozen_string_literal: true

class NationalHearingQueueEntryRefreshJob < CaseflowJob
def initialize
@timeout_seconds = 30

super
end

def perform
begin
NationalHearingQueueEntry.refresh
rescue ActiveRecord::QueryCanceled => error
handle_timeout(error)
rescue StandardError => error
log_error(error)
ensure
# Set Timeout Back
if @timeout_seconds != 30
timeout_set(30)
end
end
end

private

def handle_timeout(error)
if @timeout_seconds == 30
# temporarily setting timeout to allow query to run
timeout_set(2700)
perform
else
Rails.logger.error("Timeout was set to #{@timeout_seconds} seconds and job timed out.")
log_error(error)
end
end

def timeout_set(seconds)
@timeout_seconds = seconds

ActiveRecord::Base.connection.execute("SET statement_timeout = '#{seconds}s'")
end
end
14 changes: 14 additions & 0 deletions app/models/national_hearing_queue_entry.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

class NationalHearingQueueEntry < CaseflowRecord
belongs_to :appeal, polymorphic: true
belongs_to :task, class_name: "ScheduleHearingTask"

def self.refresh
Scenic.database.refresh_materialized_view(
"national_hearing_queue_entries",
concurrently: true,
cascade: false
)
end
end
4 changes: 4 additions & 0 deletions app/models/schedulable_cutoff_date.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# frozen_string_literal: true

class SchedulableCutoffDate < CaseflowRecord
end
4 changes: 4 additions & 0 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@
# Dynatrace variables
ENV["STATSD_ENV"] = "development"

# Veteran Residence Location variables
ENV["RESIDENCE_LOCATION_BATCH_SIZE"] = "5000"
ENV["VET_UPDATE_BATCH_SIZE"] = "100"

# eFolder API URL to retrieve appeal documents
config.efolder_url = "http://localhost:4000"
config.efolder_key = "token"
Expand Down
4 changes: 4 additions & 0 deletions config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,10 @@
# Dynatrace variables
ENV["STATSD_ENV"] = "test"

# Veteran Residence Location variables
ENV["RESIDENCE_LOCATION_BATCH_SIZE"] = "5"
ENV["VET_UPDATE_BATCH_SIZE"] = "1"

config.sqs_create_queues = true
config.sqs_endpoint = ENV["CI"] ? 'http://localstack:4566' : 'http://localhost:4566'
end
4 changes: 3 additions & 1 deletion config/initializers/scheduled_jobs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
"stuck_job_scheduler_job" => StuckJobSchedulerJob,
"fetch_webex_rooms_list_job" => Hearings::FetchWebexRoomsListJob,
"refresh_webex_access_token_job" => Hearings::RefreshWebexAccessTokenJob,
"ineligible_judges_job" => IneligibleJudgesJob
"ineligible_judges_job" => IneligibleJudgesJob,
"national_hearing_queue_entry_refresh_job" => NationalHearingQueueEntryRefreshJob,
"check_veteran_residence_location" => CheckVeteranResidenceLocationJob
}.freeze
end
22 changes: 22 additions & 0 deletions db/functions/brieffs_awaiting_hearing_scheduling_v01.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
CREATE OR REPLACE FUNCTION brieffs_awaiting_hearing_scheduling()
RETURNS SETOF brieff_record
LANGUAGE plpgsql AS
$func$
DECLARE
legacy_case_ids text;
BEGIN
SELECT *
INTO legacy_case_ids
FROM gather_vacols_ids_of_hearing_schedulable_legacy_appeals();

if legacy_case_ids IS NOT NULL THEN
RETURN QUERY
EXECUTE format(
'SELECT * FROM f_vacols_brieff WHERE bfkey IN (%s)',
legacy_case_ids
);
END IF;

-- Force a null row return
RETURN QUERY EXECUTE 'SELECT * FROM f_vacols_brieff WHERE 1 = 0';
END $func$;
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
CREATE OR REPLACE FUNCTION gather_bfcorkeys_of_hearing_schedulable_legacy_cases()
RETURNS TEXT
LANGUAGE plpgsql AS
$func$
DECLARE
bfcorkey_ids TEXT;
BEGIN
SELECT string_agg ( DISTINCT quote_literal (bfcorkey), ',' )
INTO bfcorkey_ids
FROM brieffs_awaiting_hearing_scheduling();

RETURN bfcorkey_ids;
END
$func$;
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
CREATE OR REPLACE FUNCTION gather_vacols_ids_of_hearing_schedulable_legacy_appeals()
RETURNS TEXT
LANGUAGE plpgsql AS
$func$
DECLARE
legacy_case_ids text;
BEGIN
SELECT string_agg(DISTINCT format($$'%s'$$, vacols_id), ',')
INTO legacy_case_ids
FROM legacy_appeals
JOIN tasks ON tasks.appeal_type = 'LegacyAppeal' and tasks.appeal_id = legacy_appeals.id
WHERE
tasks.type = 'ScheduleHearingTask'
AND tasks.status IN ('assigned', 'in_progress', 'on_hold')
GROUP BY tasks.type;

RETURN legacy_case_ids;
END
$func$;
11 changes: 11 additions & 0 deletions db/migrate/20241008145227_create_national_hearing_queue_entries.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

class CreateNationalHearingQueueEntries < ActiveRecord::Migration[6.1]
def up
create_view :national_hearing_queue_entries, materialized: true
end

def down
drop_view :national_hearing_queue_entries, materialized: true
end
end
Loading
Loading