task不重复执行

This commit is contained in:
huang 2017-02-24 13:42:58 +08:00
parent 30c14c2e07
commit d76e34889a
1 changed files with 4 additions and 2 deletions

View File

@ -933,6 +933,8 @@ class ProjectsController < ApplicationController
message = params[:msg].to_i
begin
@training_task = TrainingTask.find(task_id)
# 如果已经执行成功过,则不重复执行
return if @training_task.status == 1
original_project_id = Project.find(@training_task.project_id).try(:forked_from_project_id)
original_project = Project.find(original_project_id)
rescue
@ -941,10 +943,10 @@ class ProjectsController < ApplicationController
original_tasks_count = original_project.training_tasks.count
position = @training_task.try(:position) + 1
# 测试,默认成功
if status == 0
if status == 0
ActiveRecord::Base.transaction do
if position <= original_tasks_count
# 继续下一个任务
# 继续发布下一个任务
publish_training_tasks original_project_id, @training_task.project_id, position
@training_task.update_attribute(:status, 1)
end