Skip to content

Commit

Permalink
Log org id and update rescue blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
ellohez committed Nov 25, 2024
1 parent 26a3320 commit 9e6bdb8
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lib/tasks/access_and_permissions.rake
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ namespace :permissions do
message = "Access permission successfully assigned to document with ID - #{document.id}"
end
args[:log_file] ? args[:log_file].puts(message) : puts(message)
rescue StandardError => e
rescue Mongoid::Errors::DocumentNotFound => e
error_message = "An error occurred while processing document ID #{args[:document_content_id]}: #{e.message}"
args[:log_file] ? args[:log_file].puts(error_message) : puts(error_message)
end

desc "Bulk process access permissions from CSV of URLs - See doc"
desc "Bulk process access permissions from CSV of URLs"
task :bulk_process_access_flags, %i[csv_filename organisation_id] => :environment do |_, args|
log_file = File.new("/tmp/permissions_rake_log.txt", "w")
log_file = File.open("/tmp/permissions_rake_log.txt", "w")
log_file.puts("Adding access permissions for Org ID - #{args[:organisation_id]}")

begin
CSV.foreach(args[:csv_filename], headers: true) do |row|
Expand All @@ -40,8 +41,8 @@ namespace :permissions do

Rake::Task["permissions:add_organisation_access"].reenable
Rake::Task["permissions:add_organisation_access"].invoke(document.id, args[:organisation_id], log_file)
rescue Mongoid::Errors::DocumentNotFound => e
log_file.puts "--- Document not found error ---"
rescue StandardError => e
log_file.puts "--- Error occurred ---"
log_file.puts e.detailed_message
log_file.puts "------"
end
Expand Down

0 comments on commit 9e6bdb8

Please sign in to comment.