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

[CPDNPQ-2270] port rake file and service from ECF (bulk script for revert to pending) #2025

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

alkesh
Copy link
Contributor

@alkesh alkesh commented Nov 28, 2024

Context

Ticket: https://dfedigital.atlassian.net/browse/CPDNPQ-2270

bulk script for revert to pending - rake file and service ported from ECF - updated to work with the NPQ Applications::RevertToPending service.

Copy link

@alkesh alkesh force-pushed the CPDNPQ-2270-bulk-revert-script branch from 3639178 to bb5b35f Compare November 29, 2024 09:01
@alkesh alkesh marked this pull request as ready for review November 29, 2024 09:15
@alkesh alkesh requested a review from a team as a code owner November 29, 2024 09:15
@alkesh alkesh changed the title [CPDNPQ-2270] port rake file and service from ECF [CPDNPQ-2270] port rake file and service from ECF (bulk script for revert to pending) Nov 29, 2024
Copy link
Contributor

@jebw jebw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple of minor code clarity suggestions but looks great 🙌

result = application_ecf_ids.each_with_object({}) do |application_ecf_id, hash|
application = Application.find_by(ecf_id: application_ecf_id)
revert_to_pending = Applications::RevertToPending.new(application:, change_status_to_pending: "yes")
success = application && revert_to_pending.revert
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super minor but RevertToPending already validates presence of application ?

return "Not found" if application.nil?
return "Changed to pending" if success

errors.map(&:message).join(", ")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

errors.full_messages.to_sentence ?

@@ -0,0 +1,35 @@
# frozen_string_literal: true

require "rake"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this should be needed?

dry_run = args[:dry_run] != "false"
unless File.exist?(csv_file_path)
logger.error "File not found: #{csv_file_path}"
return
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exit(1) ?

application_ecf_ids = CSV.read(csv_file_path, headers: false).flatten

logger.info "Bulk changing #{application_ecf_ids.size} applications to pending#{' (dry run)' if dry_run}..."

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sleep(10) - gives the developer time to think 'oops' and press ctrl-c ? Might be belt and braces though, there's already a dry run feature? thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this one might be overkill.
I'd expect the developer will already run this with dry-run first, and the effort in creating/uploading the CSV file in the first place means it shouldn't be a trivial thing to run accidentally.

end

context "when dry run true" do
subject { Rake::Task["one_off:bulk_change_to_pending"].invoke(csv_file.path, "true") }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

subject(:run_task)

subject { Rake::Task["one_off:bulk_change_to_pending"].invoke(csv_file.path, "true") }

it "does not update any applications" do
subject
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

run_task ? Clarifies what subject is doing ?

Copy link

sonarcloud bot commented Nov 29, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants