Skip to content

Commit

Permalink
Merge pull request #7551 from ministryofjustice/lnd/restart-submissio…
Browse files Browse the repository at this point in the history
…ns-test

LnD: investigation into restart submission report generation
  • Loading branch information
colinbruce authored Jan 17, 2025
2 parents bbfebcb + 54042e2 commit 08336be
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 2 deletions.
1 change: 1 addition & 0 deletions app/controllers/admin/ccms_queues_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module Admin
class CCMSQueuesController < AdminBaseController
def index
@in_progress = CCMS::Submission.where.not(aasm_state: %w[completed abandoned]).order(created_at: :desc)
@paused = BaseStateMachine.where(aasm_state: :submission_paused).order(:created_at).map(&:legal_aid_application)
end

def show
Expand Down
6 changes: 6 additions & 0 deletions app/models/concerns/base_state_machine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ def allow_ccms_submission?
EnableCCMSSubmission.call || ENV.fetch("LOCAL_CCMS_OVERRIDE", "false") == "true"
end

def log_status_change
Rails.logger.info "BaseStateMachine::StateChange, laa_id: #{legal_aid_application.id}, event: #{aasm.current_event}, from: #{aasm.from_state}, to: #{aasm.to_state}"
end

VALID_CCMS_REASONS = %i[
no_online_banking
no_applicant_consent
Expand Down Expand Up @@ -43,6 +47,8 @@ def allow_ccms_submission?
state :use_ccms
state :delegated_functions_used

after_all_transitions :log_status_change

event :enter_applicant_details do
transitions from: %i[
initiated
Expand Down
39 changes: 38 additions & 1 deletion app/views/admin/ccms_queues/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
back_link: :none,
) %>

<h2 class="govuk-heading-m"><%= t(".progress_queue.heading") %></h2>
<% if @in_progress.empty? %>
<h2 class="govuk-heading-m">Queue is empty</h2>
<h3 class="govuk-heading-s"><%= t(".progress_queue.empty") %></h3>
<% else %>

<div class="govuk-grid-row">
Expand Down Expand Up @@ -40,3 +41,39 @@
</div>

<% end %>

<h2 class="govuk-heading-m"><%= t(".paused_submission.heading") %></h2>
<% if @paused.empty? %>
<h3 class="govuk-heading-s"><%= t(".paused_submission.empty") %></h3>
<% else %>
<div class="govuk-grid-row">
<div class="govuk-grid-column-full">

<%= govuk_table do |table|
table.with_caption(html_attributes: { class: "govuk-visually-hidden" }, text: t(".page_title"))

table.with_head do |head|
head.with_row do |row|
row.with_cell(text: t(".case_reference"))
row.with_cell(text: t(".state"))
row.with_cell(text: t(".created_at"))
end
end

table.with_body do |body|
@paused.each do |application|
body.with_row do |row|
row.with_cell do
govuk_link_to(application.application_ref, admin_legal_aid_applications_submission_path(application))
end
row.with_cell(text: application.state.humanize)
row.with_cell(text: l(application.created_at, format: :long_date_time))
end
end
end
end %>

</div>
</div>

<% end %>
1 change: 1 addition & 0 deletions app/workers/reports_creator_worker.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class ReportsCreatorWorker
include Sidekiq::Worker
include Sidekiq::Status::Worker
sidekiq_options queue: :report_creator

def perform(legal_aid_application_id)
legal_aid_application = LegalAidApplication.find(legal_aid_application_id)
Expand Down
4 changes: 4 additions & 0 deletions config/initializers/sidekiq.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@

Sidekiq.configure_server do |config|
config.redis = { url: redis_url }
config.capsule("report_capsule") do |cap|
cap.concurrency = 2
cap.queues = %w[report_creator]
end

# accepts :expiration (optional)
Sidekiq::Status.configure_server_middleware config, expiration: 30.minutes.to_i
Expand Down
7 changes: 7 additions & 0 deletions config/locales/en/admin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,15 @@ en:
ccms_queues:
index:
page_title: Incomplete CCMS Submissions
progress_queue:
heading: Processing queue
empty: The sidekiq queue is empty
paused_submission:
heading: Paused submissions
empty: There are no paused submissions
applicant_name: Client's name
references: CCMS & case reference
case_reference: Case reference
created_at: Date started
state: State
sidekiq:
Expand Down
18 changes: 17 additions & 1 deletion spec/requests/admin/ccms_queues_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
context "when there are no applications on the queue" do
it "displays a warning message" do
get_index
expect(response.body).to include("Queue is empty")
expect(response.body).to include("The sidekiq queue is empty")
end
end

Expand All @@ -35,6 +35,22 @@
expect(response.body).to include(admin_ccms_queue_path(ccms_submission.id))
end
end

context "when there are no paused applications" do
it "displays a warning message" do
get_index
expect(response.body).to include("There are no paused submissions")
end
end

context "when there is a paused application" do
let!(:legal_aid_application) { create(:legal_aid_application, :submission_paused) }

it "has a link to the application" do
get_index
expect(response.body).to include(admin_legal_aid_applications_submission_path(legal_aid_application))
end
end
end

describe "GET show" do
Expand Down

0 comments on commit 08336be

Please sign in to comment.