Skip to content

Commit

Permalink
Added 'retry' button for admins, in BAC interface
Browse files Browse the repository at this point in the history
Also added better messages in rake task that cleans
resource usage records.
  • Loading branch information
prioux committed Mar 2, 2025
1 parent 3dc6633 commit d20378b
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 9 deletions.
13 changes: 7 additions & 6 deletions BrainPortal/app/controllers/background_activities_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,17 +120,18 @@ def index #:nodoc:
def operation #:nodoc:
# It's quite stupid but we detect the type of operation
# based on the value returned by the submit button
op = :cancel! if params[:commit] =~ /cancel/i
op = :suspend! if params[:commit] =~ /\bsuspend/i
op = :unsuspend! if params[:commit] =~ /unsuspend/i
op = :destroy if params[:commit] =~ /destroy/i
op = :activate! if params[:commit] =~ /activate/i
op = :cancel! if params[:commit] =~ /cancel/i
op = :suspend! if params[:commit] =~ /\bsuspend/i
op = :unsuspend! if params[:commit] =~ /unsuspend/i
op = :destroy if params[:commit] =~ /destroy/i
op = :activate! if params[:commit] =~ /activate/i
op = :force_single_retry if params[:commit] =~ /retry/i
bac_ids = Array(params[:bac_ids])
bacs = BackgroundActivity.where(:id => bac_ids)
bacs = bacs.where(:user_id => current_user.id) if ! current_user.has_role? :admin_user
bacs = bacs.to_a.select { |bac| bac.send(op) }
# These messages are clumsy
flash[:notice] = "#{bacs.size} activities affected by #{op.to_s.gsub(/\W/,"")}." if bacs.size > 0
flash[:notice] = "#{bacs.size} activities affected by '#{op.to_s.gsub(/\W/,"").humanize}'." if bacs.size > 0
flash[:notice] = "No activities affected." if bacs.size == 0
redirect_to :action => :index
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
<%= external_submit_button "Unsuspend Activities", "bac_form", :class => "button", :confirm => "Are you sure you want to reactivate the selected background activities?" %>
<%= external_submit_button "Destroy Activities", "bac_form", :class => "button", :confirm => "Are you sure you want to destroy the selected background activities?" %>
<%= external_submit_button "Activate Now!", "bac_form", :class => "button", :confirm => "Are you sure you want to activate the selected background activities?" %>
<%= external_submit_button "Retry Failed", "bac_form", :class => "button", :confirm => "Are you sure you want to retry the failed items of the selected background activities?" %>
<%= link_to "Create New Scheduled Activity", new_background_activity_path, :class => "button" %>
<%= scope_filter_link("Hide Scheduled", "background_activities#index", :replace,
[ { :a => :status, :o => 'in', :v => %w( InProgress Completed PartiallyCompleted Failed InternalError Cancelled Suspended ) } ],
Expand Down
43 changes: 40 additions & 3 deletions BrainPortal/lib/tasks/resource_usage_serialization.rake
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,38 @@ namespace :cbrain do
WalltimeResourceUsageForCbrainTask => :cbrain_task,
SpaceResourceUsageForUserfile => :userfile,
}

puts <<-HEADER
=================================================
ResourceUsage Database Cleanup Rake Task Starting
=================================================
Timestamp for dump files:
* #{timestamp}
Selected RU objects:
#{
allrecords != 'ALL' ?
" * Dump only RU records linked to deleted objects (files, tasks)" :
" * All RU records will be dumped"
}
Disposition of dumped records:
#{
destroy == 'DESTROY_ALL' ?
" * Dumped records will be destroyed" :
" * No records will be destroyed (warning: you now have dups in the dump file and in the DB!)"
}
HEADER

type_to_nullmodel.each do |type,nullmodel|

puts ""
puts "-------------------------------------------------------"
puts "ResourceUsage Model: #{type}"
puts "-------------------------------------------------------"

# Identify what to dump
old_records = type.all
if allrecords != 'ALL' # default
Expand All @@ -79,24 +109,31 @@ namespace :cbrain do
# Inform user
count = old_records.count
filename = Rails.root + "data_dumps" + "#{type.to_s}.#{timestamp}.yaml"
printf "%36s : %7d records %s\n", type.to_s, count, (count == 0 ? "(nothing to dump)" : "dumped in #{filename}")
printf "%36s : %7d records %s\n", type.to_s, count, (count == 0 ? "(nothing to dump)" : "being dumped in #{filename}")
next if count == 0

# Dump records
File.open(filename,"w") do |fh|
fh.write(old_records.to_a.map(&:attributes).to_yaml)
end
puts " -> dump finished, you can gzip that file if you want."

# Destroy them
if destroy == 'DESTROY_ALL'
puts " -> destroying records in database..."
if allrecords == 'ALL'
puts " -> destroying ALL records in database..."
type.delete_all
else
puts " -> destroying DUMPED records in database..."
# Note: you can't .delete_all on a left_outer_join relation... :-(
old_records.find_each do |obj| # will do 1000 objects at time
counter=0;modulo=10000
print " -> (#{modulo} records per X): "
old_records.find_each do |obj| # will fetch 1000 objects at time
print "X" if counter % modulo == 0
counter += 1
obj.delete
end
puts ""
end
end

Expand Down

0 comments on commit d20378b

Please sign in to comment.