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 @@ Status <%= @analysis.status %> <% if @analysis.status == 'started' %> - | <%= link_to("Stop Analysis", stop_analysis_path(@analysis)) %> - <% end %> + | <%= link_to("Stop Analysis", stop_analysis_path(@analysis), onclick: "return confirm('Are you sure you want to stop the analysis?')") %> + | <%= link_to("Soft Stop", soft_stop_analysis_path(@analysis), onclick: "return confirm('Are you sure you want to stop the analysis?')") %> + <% end %> diff --git a/server/app/views/pages/dashboard.html.erb b/server/app/views/pages/dashboard.html.erb index 153409c37..f197d9e8d 100644 --- a/server/app/views/pages/dashboard.html.erb +++ b/server/app/views/pages/dashboard.html.erb @@ -70,6 +70,7 @@
<% if @current.status == 'started' %> <%= link_to 'Stop Analysis', stop_analysis_path(@current), data: { confirm: 'Are you sure?' }, class: "btn btn-mini" %> + <%= link_to 'Soft Stop Analysis', soft_stop_analysis_path(@current), data: { confirm: 'Are you sure?' }, class: "btn btn-mini" %> <% else %> <%= link_to 'Delete Project', project_path(@current.project), method: :delete, data: {confirm: 'Are you sure?'}, class: "btn btn-mini" %> <% end %> @@ -125,6 +126,7 @@
<% if res.status == 'started' %> <%= link_to 'Stop Analysis', stop_analysis_path(res.project), data: { confirm: 'Are you sure?' }, class: "btn btn-mini" %> + <%= link_to 'Soft Stop Analysis', soft_stop_analysis_path(res.project), data: { confirm: 'Are you sure?' }, class: "btn btn-mini" %> <% else %> <%= link_to 'Delete Project', project_path(res.project), method: :delete, data: {confirm: 'Are you sure?'}, class: "btn btn-mini" %> <% end %> diff --git a/server/app/views/projects/index.html.erb b/server/app/views/projects/index.html.erb index 0e50044bb..83e529a4a 100644 --- a/server/app/views/projects/index.html.erb +++ b/server/app/views/projects/index.html.erb @@ -20,6 +20,7 @@ <% logger.warn("WTH - returns '#{project.analyses.first}'") %> <% if project.analyses.first.status == 'started' %> <%= link_to 'Stop', stop_analysis_path(project.analyses.first), data: { confirm: 'Are you sure?' } %> + <%= link_to 'Soft Stop', soft_stop_analysis_path(project.analyses.first), data: { confirm: 'Are you sure?' } %> <% else %> <%= link_to 'Delete', project, method: :delete, data: { confirm: 'Are you sure?' } %> <% end %> diff --git a/server/config/routes.rb b/server/config/routes.rb index 401872e1a..b829b47a2 100644 --- a/server/config/routes.rb +++ b/server/config/routes.rb @@ -26,6 +26,7 @@ post :action post :upload get :stop + get :soft_stop get :status get :page_data get :analysis_data