Skip to content

Instantly share code, notes, and snippets.

@jcreed
Last active October 3, 2023 20:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jcreed/948130680d326aa42de79161949b563a to your computer and use it in GitHub Desktop.
Save jcreed/948130680d326aa42de79161949b563a to your computer and use it in GitHub Desktop.
wa 6877 base task
namespace :after_party do
desc 'Deployment task: unassign_applicants'
task :wa_6877, [:group] => [:environment] do |_task, args|
next if args[:group] != 'before_load' # available before_migrate|before_load|after_load
include ReleaseTaskHelpers
puts "Running deploy task 'wa_6877'"
# if Rails.env.production?
display :info, "wa_6877 Starting task..."
with_association('ADEA AADSAS', '2024') do |cas|
assignment_type = Assignments::AssignmentType.find_by(id: 99653) # name: "Application Review."
csv_file = Rails.root.join('lib', 'tasks', 'deployment','data', 'wa_6877_all_assignments.csv')
csv_text = File.read(csv_file)
csv = CSV.parse(csv_text, headers: true, encoding: 'utf-8')
identifiers = []
csv.each do |row|
identifiers << row['cas_id']
end
applicant_ids = cas.applicants.where(identifier: identifiers).map(&:id)
bad_assignments = assignment_type.
assignment_bases.
where(applicant_id: applicant_ids).
where(date_assigned: '2023-09-01').
where(complete: false)
debugger
if bad_assignments
count = bad_assignments.destroy
display :info, "#{count} assignments were destroyed"
else
display :error, "No assignments were found"
end
end
# else
# display :info, "wa_6877 Only runs on production"
# end
# Update task as completed. If you remove the line below, the task will
# run with every deploy (or every time you call after_party:run).
AfterParty::TaskRecord.create AfterParty::TaskRecorder.new(__FILE__).to_h
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment