Skip to content

Instantly share code, notes, and snippets.

@amponce
Last active November 30, 2023 20:54
Show Gist options
  • Save amponce/0a56a8e6ac689f7b69596b411a36317a to your computer and use it in GitHub Desktop.
Save amponce/0a56a8e6ac689f7b69596b411a36317a to your computer and use it in GitHub Desktop.
Frontend Guide to Argo

Argo

Access the Argo CD Dashboard for Deployment Management:

Select the Node

Find the vets-api-web node and start the Rails console with:

bundle exec rails c

Once logged in, use the following commands to interact with in-progress forms:

Sample Console Commands Get the last form entry for form number '5655':

InProgressForm.for_form('5655').last

To access the metadata for the last in-progress form:

InProgressForm.for_form('5655').last.metadata

Useful files for rails console commands

  • The in_progress_form.rb file is where the InProgressForm ActiveRecord model is defined.
  • The DebtsAPI form5655_submission.rb
  • The db/schema.rb file contains the schema definition for the database

Code Snippet for Processing Form Submissions

Warning - Don't mess with the update example unless you need to modify production data

Ruby cmds to iterate over Form5655Submission records and updating the public_metadata for each submission that has a 'streamlined' form:

// Get by uuid
DebtsApi::V0::Form5655Submission.where(user_uuid: 'your-uuid-here')
// Get the last streamlined short submission
DebtsApi::V0::Form5655Submission.where("public_metadata -> 'streamlined' ->> 'type' = ?", "short").last
// Get the # of all short submissions
DebtsApi::V0::Form5655Submission.where("public_metadata -> 'streamlined' ->> 'type' = ?", "short").length
// Get the # of all long submissions
DebtsApi::V0::Form5655Submission.where("public_metadata -> 'streamlined' ->> 'type' = ?", "long").length
// Get 20 random submissions by debt type
DebtsApi::V0::Form5655Submission.last(20).map { |sub| sub.public_metadata['debt_type'] }
// Get the last 20 by debt type
DebtsApi::V0::Form5655Submission.all.order(:created_at).last(20).map { |sub| sub.public_metadata['debt_type'] }
// Update data Example
DebtsApi::V0::Form5655Submission.find_each(batch_size: 300).with_index do |sub, index|
  begin
    form = sub.form
    if form['streamlined']
      puts "#{index}/#{total}" # Note: Ensure 'total' is defined as the total number of submissions.
      metadata = sub.public_metadata
      metadata['streamlined'] = form['streamlined']
      sub.update!(public_metadata: metadata)
    end
  rescue => e # It's a good practice to specify what you're rescuing from, e.g., StandardError
    trouble << sub.id # Ensure 'trouble' is initialized before this block.
    puts "Error processing submission #{sub.id}: #{e.message}"
  end
end

Additional Resources

For more information on querying with Active Record, refer to the following guide:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment