app/controllers/naf/historical_jobs_controller.rb in naf-2.0.2 vs app/controllers/naf/historical_jobs_controller.rb in naf-2.0.3
- old
+ new
@@ -105,29 +105,32 @@
def update
respond_to do |format|
@historical_job = Naf::HistoricalJob.find(params[:id])
if @historical_job.update_attributes(params[:historical_job])
- if params[:historical_job][:request_to_terminate].present?
- if queued_job = ::Naf::QueuedJob.find_by_id(params[:id])
- @historical_job.finished_at = Time.zone.now
- @historical_job.save!
- queued_job.delete
- end
- if running_job = ::Naf::RunningJob.find_by_id(params[:id])
- running_job.update_attributes(request_to_terminate: true)
- @historical_job.update_attributes(request_to_terminate: true)
+ ::Naf::HistoricalJob.lock_for_job_queue do
+ if params[:historical_job][:request_to_terminate].present?
+ if queued_job = ::Naf::QueuedJob.find_by_id(params[:id])
+ @historical_job.finished_at = Time.zone.now
+ @historical_job.save!
+ queued_job.delete
+ end
+
+ if running_job = ::Naf::RunningJob.find_by_id(params[:id])
+ running_job.update_attributes(request_to_terminate: true)
+ @historical_job.update_attributes(request_to_terminate: true)
+ end
end
- end
- format.html do
- redirect_to(@historical_job, notice: "Job '#{@historical_job.command}' was successfully updated.")
- end
- format.json do
- render json: { success: true,
- title: @historical_job.title,
- command: @historical_job.command }.to_json
+ format.html do
+ redirect_to(@historical_job, notice: "Job '#{@historical_job.command}' was successfully updated.")
+ end
+ format.json do
+ render json: { success: true,
+ title: @historical_job.title,
+ command: @historical_job.command }.to_json
+ end
end
else
format.html do
render action: "edit"
end