From dabc5fd97d541f6a815c0c1e4b9fa7076aedc301 Mon Sep 17 00:00:00 2001 From: raymond-hughes Date: Thu, 31 Aug 2023 11:16:38 -0400 Subject: [PATCH 1/4] Adding IHP task script and remediation steps for automated SOP --- lib/helpers/scripts/predocket-ihp-task-script.sh | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100755 lib/helpers/scripts/predocket-ihp-task-script.sh diff --git a/lib/helpers/scripts/predocket-ihp-task-script.sh b/lib/helpers/scripts/predocket-ihp-task-script.sh new file mode 100755 index 00000000000..36252ac160e --- /dev/null +++ b/lib/helpers/scripts/predocket-ihp-task-script.sh @@ -0,0 +1,6 @@ +#! /bin/bash +cd /opt/caseflow-certification/src; bin/rails c << DONETOKEN +x = WarRoom::PreDocketIhpTasks.new +x.run("$1") +DONETOKEN + From 5ecf344f74db4b47218b4d0fe2038ab1417a38b1 Mon Sep 17 00:00:00 2001 From: raymond-hughes Date: Thu, 31 Aug 2023 11:17:55 -0400 Subject: [PATCH 2/4] Adding IHP task script --- lib/helpers/pre_docket_ihp_tasks.rb | 63 +++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 lib/helpers/pre_docket_ihp_tasks.rb diff --git a/lib/helpers/pre_docket_ihp_tasks.rb b/lib/helpers/pre_docket_ihp_tasks.rb new file mode 100644 index 00000000000..1f734a8e60c --- /dev/null +++ b/lib/helpers/pre_docket_ihp_tasks.rb @@ -0,0 +1,63 @@ +# frozen_string_literal: true + +# ************************ +# Remediates IHP tasks that are generated prior to completion of Pre-Docket task +# If an InformalHearingPresentationTask is present prior to PreDocketTask being completed +# we create a new DistributionTask and set the InformalHearingPresentationTask as a child +# This will become a blocking task and allow the PreDocketTask to be completed prior to +# the InformalHearingPresentationTask being completed +# ************************ +module WarRoom + class PreDocketIhpTasks + def run(appeal_uuid) + @appeal = Appeal.find_appeal_by_uuid_or_find_or_create_legacy_appeal_by_vacols_id(appeal_uuid) + if appeal.appeal_state.appeal_docketed + puts("Appeal has been docketed. Aborting...") + fail Interrupt + end + + predocket_task.update!(parent_id: ihp_task.id) + + ihp_task.update!(parent_id: distribution_task.id) + ihp_task.on_hold! + end + + private + + def root_task + @root_task = appeal.root_task + end + + def distribution_task + @distribution_task ||= + if (dt = @appeal.tasks.where(type: "DistributionTask").first).blank? + distribution_task = DistributionTask.create!(appeal: @appeal, parent: root_task) + distribution_task.on_hold! + distribution_task + else + dt.on_hold! + dt + end + end + + def predocket_task + @predocket_task ||= + if (predocket_tasks = appeal.tasks.where(type: "PreDocketTask").all).count > 1 + puts("Duplicate PredocketTask found. Aborting...") + fail Interrupt + end + + predocket_tasks[0] + end + + def ihp_task + @ihp_task ||= + if (ihp_tasks = appeal.tasks.where(type: "InformalHearingPresentationTask").all).count > 1 + puts("Duplicate InformalHearingPresentationTask found. Aborting...") + fail Interrupt + end + + ihp_tasks[0] + end + end +end From f5e46960043c228467d447d91a4db15d8eed4351 Mon Sep 17 00:00:00 2001 From: raymond-hughes Date: Thu, 31 Aug 2023 12:18:05 -0400 Subject: [PATCH 3/4] Adding fails to script so we capture correct issue when remediation is ran --- lib/helpers/pre_docket_ihp_tasks.rb | 55 +++++++++++++++++++---------- 1 file changed, 36 insertions(+), 19 deletions(-) diff --git a/lib/helpers/pre_docket_ihp_tasks.rb b/lib/helpers/pre_docket_ihp_tasks.rb index 1f734a8e60c..105c12ced55 100644 --- a/lib/helpers/pre_docket_ihp_tasks.rb +++ b/lib/helpers/pre_docket_ihp_tasks.rb @@ -11,7 +11,7 @@ module WarRoom class PreDocketIhpTasks def run(appeal_uuid) @appeal = Appeal.find_appeal_by_uuid_or_find_or_create_legacy_appeal_by_vacols_id(appeal_uuid) - if appeal.appeal_state.appeal_docketed + if @appeal.appeal_state&.appeal_docketed puts("Appeal has been docketed. Aborting...") fail Interrupt end @@ -20,44 +20,61 @@ def run(appeal_uuid) ihp_task.update!(parent_id: distribution_task.id) ihp_task.on_hold! + rescue ActiveRecord::RecordNotFound => _error + puts("Appeal was not found. Aborting...") + raise Interrupt + rescue StandardError => error + puts("Something went wrong. Requires manual remediation. Error: #{error} Aborting...") + raise Interrupt end private def root_task - @root_task = appeal.root_task + @root_task = @appeal.root_task end def distribution_task @distribution_task ||= - if (dt = @appeal.tasks.where(type: "DistributionTask").first).blank? - distribution_task = DistributionTask.create!(appeal: @appeal, parent: root_task) - distribution_task.on_hold! - distribution_task - else + if (distribution_tasks = @appeal.tasks.where(type: "DistributionTask").all).count > 1 + puts("Duplicate DistributionTask found. Remove the erroneous task and retry. Aborting...") + fail Interrupt + elsif distribution_tasks.count == 1 + distribution_tasks[0] + elsif distribution_tasks.empty? + dt = DistributionTask.create!(appeal: @appeal, parent: root_task) dt.on_hold! dt + else + puts("DistributionTask failed to inflate. Aborting...") + fail Interrupt end end def predocket_task - @predocket_task ||= - if (predocket_tasks = appeal.tasks.where(type: "PreDocketTask").all).count > 1 - puts("Duplicate PredocketTask found. Aborting...") - fail Interrupt - end + return @predocket_task unless @predocket_task.nil? - predocket_tasks[0] + if (predocket_tasks = @appeal.tasks.where(type: "PreDocketTask").all).count > 1 + puts("Duplicate PredocketTask found. Remove the erroneous task and retry. Aborting...") + fail Interrupt + end + + @predocket_task = predocket_tasks[0] end def ihp_task - @ihp_task ||= - if (ihp_tasks = appeal.tasks.where(type: "InformalHearingPresentationTask").all).count > 1 - puts("Duplicate InformalHearingPresentationTask found. Aborting...") - fail Interrupt - end + return @ihp_task unless @ihp_task.nil? + + ihp_tasks = @appeal.tasks.where(type: "InformalHearingPresentationTask").all + if ihp_tasks.count > 1 + puts("Duplicate InformalHearingPresentationTask found. Remove the erroneous task and retry. Aborting...") + fail Interrupt + elsif ihp_tasks.count <= 0 + puts("No InformalHearingPresentationTask found. Aborting...") + fail Interrupt + end - ihp_tasks[0] + @ihp_task = ihp_tasks[0] end end end From cf538b9531f8bd0d3a54707a8cc8cace9cfa0ceb Mon Sep 17 00:00:00 2001 From: raymond-hughes Date: Sat, 2 Sep 2023 14:06:27 -0400 Subject: [PATCH 4/4] Adding status checks for automated remediaiton to give proper errors a way to bubble up to the runner of the script --- lib/helpers/pre_docket_ihp_tasks.rb | 43 +++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/lib/helpers/pre_docket_ihp_tasks.rb b/lib/helpers/pre_docket_ihp_tasks.rb index 105c12ced55..f294217ab31 100644 --- a/lib/helpers/pre_docket_ihp_tasks.rb +++ b/lib/helpers/pre_docket_ihp_tasks.rb @@ -31,7 +31,12 @@ def run(appeal_uuid) private def root_task - @root_task = @appeal.root_task + if @appeal.root_task + @root_task = @appeal.root_task + else + puts("No RootTask found. Aborting...") + fail Interrupt + end end def distribution_task @@ -40,6 +45,7 @@ def distribution_task puts("Duplicate DistributionTask found. Remove the erroneous task and retry. Aborting...") fail Interrupt elsif distribution_tasks.count == 1 + distribution_tasks[0].on_hold! distribution_tasks[0] elsif distribution_tasks.empty? dt = DistributionTask.create!(appeal: @appeal, parent: root_task) @@ -51,17 +57,31 @@ def distribution_task end end + # we look for only 1 PredocketTask. + # * If multiples are found we bail. + # * If none are found we bail. def predocket_task return @predocket_task unless @predocket_task.nil? - if (predocket_tasks = @appeal.tasks.where(type: "PreDocketTask").all).count > 1 - puts("Duplicate PredocketTask found. Remove the erroneous task and retry. Aborting...") + predocket_tasks = @appeal.tasks.where(type: "PreDocketTask").all + if predocket_tasks.count > 1 + puts("Multiple PredocketTask found. Remove the erroneous task and retry. Aborting...") fail Interrupt + elsif predocket_tasks.count < 1 + puts("No PredocketTask found. This may already be fixed. Aborting...") + fail Interrupt + else + @predocket_task = predocket_tasks[0] end - - @predocket_task = predocket_tasks[0] end + # we look for only 1 InformalHearingPresentationTask. + # * If multiples are found we bail. + # * If none are found we bail. + # The status of the InformalHearingPresentationTask must be + # * assigned + # * on_hold + # If the status is anything else we bail. def ihp_task return @ihp_task unless @ihp_task.nil? @@ -74,7 +94,18 @@ def ihp_task fail Interrupt end - @ihp_task = ihp_tasks[0] + # TODO: Need to determine the branch for cancelled status' + # If the status is cancelled does the InformalHearingPresentationTask reopen after docketing the appeal? + possible_ihp_task = ihp_tasks[0] + if possible_ihp_task.status.include?([Constants.TASK_STATUSES.assigned, Constants.TASK_STATUSES.on_hold]) + @ihp_task = possible_ihp_task + elsif possible_ihp_task.status.include?([Constants.TASK_STATUSES.cancelled]) + puts("InformalHearingPresentationTask has a status of cancelled. This is not supported for automated remediation yet. Aborting...") + fail Interrupt + else + puts("InformalHearingPresentationTask is not in the correct status for remediation. Aborting...") + fail Interrupt + end end end end