diff --git a/server/app/controllers/analyses_controller.rb b/server/app/controllers/analyses_controller.rb index b4a95bb9c..6c66dce0f 100644 --- a/server/app/controllers/analyses_controller.rb +++ b/server/app/controllers/analyses_controller.rb @@ -198,6 +198,10 @@ def destroy # stop analysis button action def stop @analysis = Analysis.find(params[:id]) + if @analysis.nil? + logger.error "Analysis with ID #{params[:id]} not found." + redirect_to analyses_path, alert: 'Analysis not found.' and return + end res = @analysis.stop_analysis respond_to do |format| @@ -208,6 +212,24 @@ def stop end end end + + # stop analysis button action + def soft_stop + @analysis = Analysis.find(params[:id]) + if @analysis.nil? + logger.error "Analysis with ID #{params[:id]} not found." + redirect_to analyses_path, alert: 'Analysis not found.' and return + end + res = @analysis.soft_stop_analysis + + respond_to do |format| + if res[0] + format.html { redirect_to @analysis, notice: 'Analysis flag changed to stop. Will NOT wait until the last submitted run finishes before killing.' } + else + format.html { redirect_to @analysis, notice: 'Analysis flag did NOT change.' } + end + end + end # Controller for submitting the action via post. This right now only works with the API # and will only return a JSON response based on whether or not the analysis has been diff --git a/server/app/models/analysis.rb b/server/app/models/analysis.rb index fcd9e22df..3d9ef8770 100644 --- a/server/app/models/analysis.rb +++ b/server/app/models/analysis.rb @@ -169,6 +169,26 @@ def stop_analysis [save!, errors] end + def soft_stop_analysis + Rails.logger.info('attempting to stop analysis') + + self.run_flag = false + + jobs.each do |j| + unless j.status == 'completed' + j.status = 'completed' + j.end_time = Time.new + j.status_message = 'datapoint canceled' + j.save! + end + end + + # Remove all the queued background jobs for this analysis + data_points.where(status: 'queued').each(&:set_soft_canceled_state) + + [save!, errors] + end + # Method that pulls out the variables from the uploaded problem/analysis JSON. def pull_out_os_variables pat_json = false diff --git a/server/app/models/data_point.rb b/server/app/models/data_point.rb index 694c9ad87..12e80bef8 100644 --- a/server/app/models/data_point.rb +++ b/server/app/models/data_point.rb @@ -125,6 +125,16 @@ def set_canceled_state self.status_message = 'datapoint canceled' save! end + + def set_soft_canceled_state + Rails.logger.debug "data_point.set_soft_canceled_state" + #destroy_background_job # destroy queued job + self.run_start_time ||= Time.now + self.run_end_time = Time.now + self.status = :completed + self.status_message = 'datapoint canceled' + save! + end def set_queued_state Rails.logger.debug "data_point.set_queued_state" diff --git a/server/app/views/analyses/show.html.erb b/server/app/views/analyses/show.html.erb index f61a77ee3..df1b2d298 100644 --- a/server/app/views/analyses/show.html.erb +++ b/server/app/views/analyses/show.html.erb @@ -35,8 +35,9 @@