Skip to content

Commit

Permalink
feature/APPEALS-43597 RC1.5.1 (#21996)
Browse files Browse the repository at this point in the history
* APPEALS-36759 Add sms_response_content and sms_response_time notifications table

* APPEALS-37003 First pass at job refactor

* APPEALS-37003 Add comments and update kwargs for va notify service

* APPEALS-37003 Update spec files

* APPEALS-37003 Update spec

* APPEALS-37003 Ensure user in job and create email_enabled method

* APPEALS-37003 Remove question mark

* Limit max retry attempts to 5

* Add ? to boolen return methods

* jcohen/APPEALS-43706 (#21444)

* APPEALS-43706 macros added to each model file for the polymorphic relationship to be setup.

* APPEALS-43706 migration made and yet to be run.

* APPEALS-43706 migrations ran and expected columns and indexes are in table.

* Fix some spec failures unrelated to this branch

* Limit schema diff

* Add a missing tab

* Fix more unrelated failures. Also prevent ACD lever seeds from overwriting spec output

* Fix last unrelated failure.

* APPEALS-43706 linting issues in va_notify_service fixed.

---------

Co-authored-by: Jonathan Cohen <cohen_jonathan@bah.com>
Co-authored-by: Matthew Thornton <ThorntonMatthew@users.noreply.github.com>

* [APPEALS-43598] Quarterly Notification Job refactoring (#21505)

* Quarterly Notification Job refactoring

* APPEALS-43598 Fix lint issues for QuarterlyNotificationsJob refactor

* APPEALS-43598 Fix db schema.rb file

* APPEALS-43598 Fix schema.rb file

* APPEALS-43598 Refactoring QuarterlyNotificationsJob for readability

* APPEALS-43598 Refactoring QuarterlyNotificationsJob and removing extra methods

* [APPEALS-43598] Update method name

---------

Co-authored-by: Matthew Thornton <99351305+ThorntonMatthew@users.noreply.github.com>

* APPEALS-44007: Eliminate Transmission of Notifications to Deceased Veterans (#21481)

* APPEALS-44007: Writing tests to ensure adding the 'failure due to deceased' information is properly set and added to the db

* updates to pr

* pushing changes for tonight

* updating spec file to handle enabling and disabling feature flags

* Update format_message_status

* Lint roll

* fixing conflicts

* Updates to send notification spec

* Fix one of the legacy test cases

* Remove accidental push

* Fix remaining test

---------

Co-authored-by: Noah Hansen <nhansen@Noahs-MacBook-Pro.local>
Co-authored-by: Matthew Thornton <ThorntonMatthew@users.noreply.github.com>
Co-authored-by: Matthew Thornton <99351305+ThorntonMatthew@users.noreply.github.com>

* MattT/APPEALS-45235: Remove Temporary PDF Files From tmp Directory After All eFolder Upload Attempts (#21557)

* Cleanup files after uploading to VBMS

* Only delete file if it exists

* Resolve linter issue

* Update specs

* Trigger CodeClimate

---------

Co-authored-by: Matthew Thornton <ThorntonMatthew@users.noreply.github.com>

* Add appeal alias for notifiable

* APPEALS-45346: Populate Polymorphic Association Columns When Creating New Notifications (#21575)

* APPEALS-45346: Populate Polymorphic Association Columns When Creating New Notifications

* fixing some errors

* updating factory

* updating tests

* updating tests and factory

* rubocop

---------

Co-authored-by: Noah Hansen <nhansen@Noahs-MacBook-Pro.local>
Co-authored-by: Matthew Thornton <99351305+ThorntonMatthew@users.noreply.github.com>

* APPEALS-43596 Adding JobMessageDeletionMiddleware to delete SQS messages for certain jobs

* APPEALS-43596 Adding tests

* APPEALS-43596 Fix codeclimate

* APPEALS-43714: Refactor VANotify Modules to Not Rely on Class Variables (#21596)

* APPEALS-43714: Refactor VANotify Modules to Not Rely on Class Variables

* pushing changes

* updating tests

* rubocop

* rubocop'n

* deleting repeat constants

* removing file in favor of EVENT_TYPE_FILTERS.json

* removing instances of using VA_NOTIFY_TEMPLATE_NAMES and using EVENT_TYPE_FILTERS instead

* replacing all instances of strings with constants

* fixing bug

* rubocop'n

* rubocop'n

* rubocop

---------

Co-authored-by: Noah Hansen <nhansen@Noahs-MacBook-Pro.local>
Co-authored-by: Matthew Thornton <99351305+ThorntonMatthew@users.noreply.github.com>

* Clean notification_events after notification report specs finish (#21662)

Co-authored-by: Matthew Thornton <ThorntonMatthew@users.noreply.github.com>

* MattT/APPEALS-43725: Extract `notify_appellant` Call from `QuaterlyNotificationsJob` to Decrease Runtime (#21643)

* Group notification types as scopes

* Add new job

* Fix typo

* Add back batching

* Batch send messages

* Multithread job queueing

* Reconfigure bulk enqueueing to utilize send_notifications.fifo queue

* Update the comment on QuaterlyNotificationsJob#perform

to adhere to the RDoc standard

* Use constants for template name

* Provide a more descriptive var name

* Remove unused env var

* Fix linting issues

* Prevent error from being thrown early in init job

* Add RDoc comments to appeal_state

* Add rdoc comment to init job

* Add another rdoc comment to the init job

* Use a more specific error class whenever an appeal

cannot be located within the init job

* Add a more specific error to CaseflowJob#enqueue_batch_of_jobs

* Add test for SendNotificationJob.queue_name_suffix

* Update QuarterlyNotificationsJob tests

* Update appeal_state_spec.rb to cover new scopes

* Add spec file for NotificationInitializationJob

* Add CaseflowJob specs

* Add CaseflowJob specs

* Address rubocop issue (by ignoring it)

* Kicking off CodeClimate

* Fix some lint issues

* Freeze constant

---------

Co-authored-by: Matthew Thornton <ThorntonMatthew@users.noreply.github.com>

* Move spec file to proper location

* APPEALS-43599 (#21696)

* APPEALS-43599 Refactoring SendNotificationJob

* APPEALS-43599 Remove comments

* APPEALS-43599 Suppress code smells from reek

* APPEALS-43599 Suppress code smells from reek

* jcohen/APPEALS-43727 (#21589)

* APPEALS-43727 Branch created. Extracted all the 'when' conditions in the case statement within appellant_notification.rb update_appeal_state method.

* APPEALS-43727 appellant_notification_service is created, logic from crowded method in appellant_notificaion.rb placed in newly created file, allowing redability.

* APPEALS-43727 added logic to appeal_state.rb, appellant_notification.rb updated with less logic, readable code through well named methods.

* APPEALS-43727 commit before merge from teammates work

* APPEALS-43727 removed freeze method on default status hash in appeal_state.rb. removed some rubocop disabling in appellant_notificaion.rb

* APPEALS-43727 extracted more logic from the appellant_notification module and placed it into the appeal_state class. Also got rid of rubocop declarations in app_notif and app_state as well. finally removed feature_toggle calls in appell_notif.

* APPEALS-43727 tests passing, code works

* APPEALS-43727 adding tests to appeal_state_spec to test functionality

* APPEALS-43727 rspec tests in appeal_state.

* APPEALS-43727 tests pass.

* Fixing code climate duplicate code issue

* fixing case statement

* code climate things

* rubocop

* APPEALS-43727 work completed.

* APPEALS-43727 PR comments applied. tests not in a working state.

* APPEALS-43727 PR comments applied. appeal_state_spec in working state.

* APPEALS-43727 PR comments applied. appellant_notification_spec.rb all green.

* Adjust spacing of comments in appeal_state.rb

* Utilize #external_id method over ternary

* Swap or conditional for blank?

* Fix another whitespace gap

* APPEALS-43727 PR comments applied. again after reset.

* APPEALS-43727 PR comments applied. flipped conditionals in appeal_state.rb

* Update app/models/concerns/appeal_concern.rb

* APPEALS-43727 code/test edits

* APPEALS-43727 bulk_task_reasssignment_spec reverted to orginal state, with the exception of an expectation that was on line 98

* APPEALS-43727 lint fix

---------

Co-authored-by: Jonathan Cohen <cohen_jonathan@bah.com>
Co-authored-by: Noah Hansen <nhansen@Noahs-MacBook-Pro.local>
Co-authored-by: Matthew Thornton <ThorntonMatthew@users.noreply.github.com>
Co-authored-by: Matthew Thornton <99351305+ThorntonMatthew@users.noreply.github.com>

* APPEALS-46179 (#21712)

* APPEALS-46179 Create JobExecutionTimes table

* APPEALS-46179 Add comment

* APPEALS-46179 Update schema

* APPEALS-46193 (#21753)

* APPEALS-46193 Add record to JobExecutionTime table when job is performed

* APPEALS-46193 Updating JobExecutionTimes table with an upsert query

* APPEALS-46193 Ignore JobExecutionTimes for certain jobs

* APPEALS-46193 Update ignore_job_execution_time? method

* APPEALS-46193 Adding tests

* Fix lint issues

* Update AWS dependencies

* Rollback gem reduction due to UAT issue

* Alter queue priority

* Forward error in SendNotificationJob

* Allow for notification audit records to remain in ProdTest

* Fix spec

* Fix typo in test fixture's name

* Fix lint infraction related to re-raising exceptions

* Address duplication CC error

* Reenable-privacy-mail-notifications (#21859)

* Add conditional for FOIA and Privacy Act mail

task to receives 'Privacy Act Pending' notifications

* Update spec

* Adjust some specs

* Add missing param

---------

Co-authored-by: Matthew Thornton <ThorntonMatthew@users.noreply.github.com>

* Remove byebug from spec

* Revert queue tweak

* Remove duplicate method

* APPEALS-47382: Refactor Job Behavior Filtering Boolean Methods (#21898)

* initial commit

* refactoring methods to have constants instead of methods

* adding comments back in

---------

Co-authored-by: Noah Hansen <nhansen@Noahs-MacBook-Pro.local>
Co-authored-by: Matthew Thornton <99351305+ThorntonMatthew@users.noreply.github.com>
Co-authored-by: nhansen3 <noah.hansen1323@gmail.com>

* APPEALS-48342: Prevent Intentional Retries of SendNotificationJobs in ProdTest from Causing Duplicate Notification Table Entries (#21927)

* initial commit

* rubocop'n

* rubcop'n

* fixing tests

---------

Co-authored-by: nhansen3 <noah.hansen1323@gmail.com>
Co-authored-by: Matthew Thornton <99351305+ThorntonMatthew@users.noreply.github.com>

* Resolve missed conflict

* MattT/APPEALS-48514 (#21959)

* Prototype of privacy act fix

* Leave privacy act states intact upon decision mailed

* Remove unused param

* Attempt updating specs to cover new behavior

* Fix attr name typo

* Add missing bang

* Skip reek issue

The issue has been deemed to be minor enough to not warrant having to reinvent everything for now.

---------

Co-authored-by: Matthew Thornton <ThorntonMatthew@users.noreply.github.com>

* Fix quarterly specs by add in necessary hearings

* Adjust spacing/ordering of gems (#21978)

* MattT/APPEALS-49085 (#21960)

* Filter out appeals whose hearings have been held from hearing_scheduled scope

* Fix whitespace issues

* Fix failing specs caused by an oversight on my part

* Fix lint issue

---------

Co-authored-by: Matthew Thornton <ThorntonMatthew@users.noreply.github.com>

* MattT/APPEALS-49212 (#21991)

* Add module to set hearing_scheduled to false whenever hearings are marked as held

* Add module to set hearing_scheduled to false whenever hearings are marked as held

* Add step to NightlySyncsJob to sync hearing dispositions and appeal stateS

* Add comment to new method

* Use constant for disposition type

* Fix typo in accessor

* Add spec for new appeal state action

* Create user in top scope

* Expand nighlty syncs job to check all scheduled hearing disposition types.

No show was left off as we don't have a requirement around it yet.

* Add nightly sync job spec

* Add disp task spec

* Add specs targeting the hearings controller

* Add sync script

* Eager load constants

* Add distinct

* Remove appeal_docketed from being reset

* Add script to adjust ama hearing statuses

* Correct mistype

* Add appeal_type clause

* Fix specs

* Lint fixes

* Flip conditionals in specs

* Fix var name

* Fix var

---------

Co-authored-by: Matthew Thornton <ThorntonMatthew@users.noreply.github.com>

* Backfill addition to script

* Add AppealState record for newly docketed LegacyAppeals (#21999)

* APPEALS-48966 Adding AppealState record for recently docketed appeals

* APPEALS-48966 Refactor code and add comments

* Delete extraneous files

* Revert to using constants value

---------

Co-authored-by: Matthew Thornton <ThorntonMatthew@users.noreply.github.com>

* Fix typo

---------

Co-authored-by: Jeff Marks <jeff.t.marks@gmail.com>
Co-authored-by: Matthew Thornton <ThorntonMatthew@users.noreply.github.com>
Co-authored-by: Jonathan Cohen <121630615+JCohDev@users.noreply.github.com>
Co-authored-by: Jonathan Cohen <cohen_jonathan@bah.com>
Co-authored-by: prernadevbah <132498915+prernadevbah@users.noreply.github.com>
Co-authored-by: noahhansen-gov <166541737+noahhansen-gov@users.noreply.github.com>
Co-authored-by: Noah Hansen <nhansen@Noahs-MacBook-Pro.local>
Co-authored-by: Prerna Devulapalli <prerna.devulapalli@va.gov>
Co-authored-by: nhansen3 <noah.hansen1323@gmail.com>
Co-authored-by: Marc Steele <71673522+msteele96@users.noreply.github.com>
  • Loading branch information
11 people authored and AdamShawBAH committed Aug 8, 2024
1 parent ed1ec05 commit acf20d2
Show file tree
Hide file tree
Showing 96 changed files with 2,981 additions and 1,238 deletions.
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ gem "acts_as_tree"

# amoeba gem for cloning appeals
gem "amoeba"
gem "aws-sdk"
# BGS

gem "bgs", git: "https://github.com/department-of-veterans-affairs/ruby-bgs.git", ref: "a2e055b5a52bd1e2bb8c2b3b8d5820b1a404cd3d"
# Bootsnap speeds up app boot (and started to be a default gem in 5.2).
gem "bootsnap", require: false
gem "browser"
gem "business_time", "~> 0.9.3"
gem "caseflow", git: "https://github.com/department-of-veterans-affairs/caseflow-commons", ref: "871f7034c502f8d7101bde74e58606716b601c70"
gem "caseflow", git: "https://github.com/department-of-veterans-affairs/caseflow-commons", ref: "716b58caf2116da5fca21c3b3aeea6c9712f3b9d"
gem "connect_mpi", git: "https://github.com/department-of-veterans-affairs/connect-mpi.git", ref: "a3a58c64f85b980a8b5ea6347430dd73a99ea74c"
gem "connect_vbms", git: "https://github.com/department-of-veterans-affairs/connect_vbms.git", ref: "9807d9c9f0f3e3494a60b6693dc4f455c1e3e922"
gem "console_tree_renderer", git: "https://github.com/department-of-veterans-affairs/console-tree-renderer.git", tag: "v0.1.1"
Expand Down
7 changes: 4 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ GIT

GIT
remote: https://github.com/department-of-veterans-affairs/caseflow-commons
revision: 871f7034c502f8d7101bde74e58606716b601c70
ref: 871f7034c502f8d7101bde74e58606716b601c70
revision: 716b58caf2116da5fca21c3b3aeea6c9712f3b9d
ref: 716b58caf2116da5fca21c3b3aeea6c9712f3b9d
specs:
caseflow (0.4.8)
aws-sdk (~> 3.2)
aws-sdk-s3
bourbon (= 4.2.7)
d3-rails
jquery-rails
Expand Down Expand Up @@ -2035,6 +2035,7 @@ DEPENDENCIES
acts_as_tree
amoeba
anbt-sql-formatter
aws-sdk
bgs!
bootsnap
brakeman
Expand Down
2 changes: 2 additions & 0 deletions app/jobs/ama_notification_efolder_sync_job.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# frozen_string_literal: true

class AmaNotificationEfolderSyncJob < CaseflowJob
include MessageConfigurations::DeleteMessageBeforeStart

queue_with_priority :low_priority

BATCH_LIMIT = ENV["AMA_NOTIFICATION_REPORT_SYNC_LIMIT"] || 500
Expand Down
21 changes: 21 additions & 0 deletions app/jobs/application_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@
class ApplicationJob < ActiveJob::Base
class InvalidJobPriority < StandardError; end

# Override in job classes if you anticipate that the job will take longer than the SQS visibility
# timeout value (ex: currently 5 hours for our low priority queue at the time of writing this)
# to prevent multiple instances of the job from being executed.
#
# See https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-visibility-timeout.html
DELETE_SQS_MESSAGE_BEFORE_START = false

# For jobs that run multiple times in a short time span, we do not want to continually update
# the JobsExecutionTime table. This boolean will help us ignore those jobs
IGNORE_JOB_EXECUTION_TIME = false

class << self
def queue_with_priority(priority)
unless [:low_priority, :high_priority].include? priority
Expand Down Expand Up @@ -48,5 +59,15 @@ def capture_exception(error:, extra: {})
if self.class.app_name.present?
RequestStore.store[:application] = "#{self.class.app_name}_job"
end

# Check whether Job execution time should be tracked
unless self.class::IGNORE_JOB_EXECUTION_TIME
# Add Record to JobExecutionTimes to track the current job execution time
JobExecutionTime.upsert(
{ job_name: self.class.to_s,
last_executed_at: Time.now.utc },
unique_by: :job_name
)
end
end
end
29 changes: 29 additions & 0 deletions app/jobs/caseflow_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,35 @@ class CaseflowJob < ApplicationJob
metrics_service_report_runtime(metric_group_name: job.class.name.underscore) unless @reported_to_metrics_service
end

class << self
# Serializes and formats a job object so that it can be placed into an SQS message queue
#
# @param job [ActiveJob::Base] The job to be serialized
#
# @return [Hash]
# A hash representation of the job object that is compatible with SQS.
def serialize_job_for_enqueueing(job)
ActiveJob::QueueAdapters::ShoryukenAdapter.instance.send(:message, job)
end

# Allows for enqueueing up to 10 async jobs at a time via the SendMessageBatch endpoint in the
# SQS API. This is to allow for reducing the number of round trips to the API when enqueueing a large
# number of jobs for delayed execution.
#
# @param jobs_to_enqueue [Array<ActiveJob::Base>] The jobs to enqueue for later execution.
# @param name_of_queue [String] The name of the SQS queue to place the messages onto.
#
# @return [Aws::SQS::Types::SendMessageBatchResult]
# A struct containing the messages that were successfully enqueued and those that failed.
def enqueue_batch_of_jobs(jobs_to_enqueue:, name_of_queue:)
fail Caseflow::Error::MaximumBatchSizeViolationError if jobs_to_enqueue.size > 10

Shoryuken::Client.queues(name_of_queue).send_messages(
jobs_to_enqueue.map { serialize_job_for_enqueueing(_1) }
)
end
end

def metrics_service_report_runtime(metric_group_name:)
MetricsService.record_runtime(
app_name: "caseflow_job",
Expand Down
2 changes: 1 addition & 1 deletion app/jobs/hearings/geomatch_and_cache_appeal_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class Hearings::GeomatchAndCacheAppealJob < ApplicationJob
application_attr :hearing_schedule

# :nocov:
retry_on(StandardError, wait: 10.seconds, attempts: 10) do |job, exception|
retry_on(StandardError, wait: 10.seconds, attempts: 5) do |job, exception|
Rails.logger.error("#{job.class.name} (#{job.job_id}) failed with error: #{exception}")

if job.executions == 10
Expand Down
5 changes: 5 additions & 0 deletions app/jobs/ignore_job_execution_time.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

module IgnoreJobExecutionTime
IGNORE_JOB_EXECUTION_TIME = true
end
2 changes: 2 additions & 0 deletions app/jobs/legacy_notification_efolder_sync_job.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# frozen_string_literal: true

class LegacyNotificationEfolderSyncJob < CaseflowJob
include MessageConfigurations::DeleteMessageBeforeStart

queue_with_priority :low_priority

BATCH_LIMIT = ENV["LEGACY_NOTIFICATION_REPORT_SYNC_LIMIT"] || 500
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

module MessageConfigurations::DeleteMessageBeforeStart
DELETE_SQS_MESSAGE_BEFORE_START = true
end
17 changes: 17 additions & 0 deletions app/jobs/middleware/job_message_deletion_middleware.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

# Deletes the message from the associated SQS queue if the job class
# specifies that this operation should take place PRIOR to the job being initiated.
#
# This will occur if the job will take longer than the SQS queue's visibility timeout
# which would potentially allow multiple instances of the same job to be executed.
class JobMessageDeletionMiddleware
# :reek:LongParameterList
def call(_worker, _queue, msg, body)
if body["job_class"].constantize::DELETE_SQS_MESSAGE_BEFORE_START
msg.client.delete_message(queue_url: msg.queue_url, receipt_handle: msg.data.receipt_handle)
end

yield
end
end
18 changes: 18 additions & 0 deletions app/jobs/nightly_syncs_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def perform
RequestStore.store[:current_user] = User.system_user
@slack_report = []

sync_hearing_states
sync_vacols_cases
sync_vacols_users
sync_decision_review_tasks
Expand Down Expand Up @@ -88,4 +89,21 @@ def dangling_legacy_appeals
reporter.call
reporter.buffer.map { |vacols_id| LegacyAppeal.find_by(vacols_id: vacols_id) }
end

# Adjusts any appeal states appropriately if it is found that a seemingly pending
# hearing has been marked with a disposition in VACOLS without Caseflow's knowledge.
def sync_hearing_states
AppealState.where(appeal_type: "LegacyAppeal", hearing_scheduled: true).each do |state|
case state.appeal&.hearings&.max_by(&:scheduled_for)&.disposition
when Constants.HEARING_DISPOSITION_TYPES.held
state.hearing_held_appeal_state_update_action!
when Constants.HEARING_DISPOSITION_TYPES.cancelled
state.hearing_withdrawn_appeal_state_update_action!
when Constants.HEARING_DISPOSITION_TYPES.postponed
state.hearing_postponed_appeal_state_update_action!
when Constants.HEARING_DISPOSITION_TYPES.scheduled_in_error
state.scheduled_in_error_appeal_state_update_action!
end
end
end
end
52 changes: 52 additions & 0 deletions app/jobs/notification_initialization_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# frozen_string_literal: true

# == Overview
#
# The NotificationInitializationJob encapsulates the instantiation of templates
# for messages to be sent by VANotify.
#
# Information such as whether or not the claimant is deceased and if the veteran is still the
# primary claimant (or if an appellant substitution has taken place) is gathered and factored
# into what is then sent to the SendNotificationJob.
#
# This job was created in order to extract logic that causes calls to external services so that
# large batch notification queueing jobs, like the QuarterlyNotificationsJob, can run much more quickly.
class NotificationInitializationJob < CaseflowJob
include Hearings::EnsureCurrentUserIsSet
include IgnoreJobExecutionTime

queue_as SendNotificationJob.queue_name_suffix
application_attr :va_notify

# ...
#
# @param appeal_id [Integer] Foreign key ID of the appeal to be associated with the notification.
# @param appeal_type [String] Class name of appeal to be associated with the notification. Appeal or LegacyAppeal.
# @param template_name [String] VANotify template name to be requested transmission of.
# Must be present in the configuration for our VANotify account, and must be a template represented in our
# notification_events table.
# @param appeal_status [String] An optional status that is used to fill in a blank in the quarterly notification
# template to let the claimant know what the status of their appeal is.
#
# @return [SendNotificationJob, nil]
# A SendNotificationJob job object representing the job that was enqueued, or nil if a notification
# wasn't ultimately attempted to be sent.
# :reek:LongParameterList
def perform(appeal_id:, appeal_type:, template_name:, appeal_status: nil)
begin
ensure_current_user_is_set

appeal = appeal_type.constantize.find_by(id: appeal_id)

fail Caseflow::Error::AppealNotFound, "#{appeal_type} with ID #{appeal_id} could not be found." unless appeal

AppellantNotification.notify_appellant(
appeal,
template_name,
appeal_status
)
rescue StandardError => error
log_error(error)
end
end
end
25 changes: 24 additions & 1 deletion app/jobs/poll_docketed_legacy_appeals_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def perform
RequestStore.store[:current_user] = User.system_user
vacols_ids = most_recent_docketed_appeals(LEGACY_DOCKETED)
filtered_vacols_ids = filter_duplicate_legacy_notifications(vacols_ids)
create_corresponding_appeal_states(filtered_vacols_ids.uniq)
send_legacy_notifications(filtered_vacols_ids)
end

Expand All @@ -38,6 +39,25 @@ def filter_duplicate_legacy_notifications(vacols_ids)
vacols_ids.reject { |id| duplicate_ids.include?(id) }
end

# Purpose: To create an AppealState record for the docketed legacy appeals
# Params: An array of vacols_ids for docketed legacy appeals
# Return: None
def create_corresponding_appeal_states(vacols_ids)
vacols_ids.each do |vacols_id|
appeal = LegacyAppeal.find_by_vacols_id(vacols_id)
appeal_state = AppealState.find_by(appeal: appeal)
if appeal_state
appeal_state.appeal_docketed = true
appeal_state.save!
else
AppealState.new(appeal: appeal,
created_by_id: User.system_user.id,
appeal_docketed: true)
.save!
end
end
end

# rubocop:disable all
# Purpose: To send the 'appeal docketed' notification for the legacy appeals
# Params: vacols_ids - An array of filtered vacols ids for legacy appeals that didnt already have notifications sent
Expand All @@ -46,7 +66,10 @@ def send_legacy_notifications(vacols_ids)
Rails.logger.info("Found #{vacols_ids.count} legacy appeals that have been recently docketed and have not gotten docketed notifications")
vacols_ids.each do |vacols_id|
begin
AppellantNotification.notify_appellant(LegacyAppeal.find_by_vacols_id(vacols_id), "Appeal docketed")
AppellantNotification.notify_appellant(
LegacyAppeal.find_by_vacols_id(vacols_id),
Constants.EVENT_TYPE_FILTERS.appeal_docketed
)
rescue Exception => ex
Rails.logger.error("#{ex.class}: #{ex.message} for vacols id:#{vacols_id} on #{JOB_ATTR.class} of ID:#{JOB_ATTR.job_id}\n #{ex.backtrace.join("\n")}")
next
Expand Down
Loading

0 comments on commit acf20d2

Please sign in to comment.