任务启动回调逻辑控制
This commit is contained in:
parent
6e9ef8ee12
commit
30c14c2e07
|
@ -844,18 +844,28 @@ class ProjectsController < ApplicationController
|
|||
jobName = "#{@project.id}"
|
||||
pipeLine = "#{Base64.encode64(@project.script)}"
|
||||
uri = URI("http://123.59.135.74:9999/jenkins-exec/api/createJob")
|
||||
res = Net::HTTP.post_form(uri, {jobName: jobName, pipeLine: pipeLine}).body
|
||||
|
||||
@project.update_attribute(:training_status, 1)
|
||||
@notice = "实训开启成功"
|
||||
params = {jobName: jobName, pipeLine: pipeLine}
|
||||
res = uri_exec uri, params
|
||||
training_project_notice res
|
||||
end
|
||||
|
||||
def training_project_update
|
||||
jobName = "#{@project.id}"
|
||||
pipeLine = "#{Base64.encode64(@project.script)}"
|
||||
uri = URI("http://123.59.135.74:9999/jenkins-exec/api/updateJob")
|
||||
res = Net::HTTP.post_form(uri, {jobName: jobName, pipeLine: pipeLine}).body
|
||||
@notice = "重新开启实训成功"
|
||||
params = {jobName: jobName, pipeLine: pipeLine}
|
||||
res = uri_exec uri, params
|
||||
training_project_notice res
|
||||
end
|
||||
|
||||
def training_project_notice res
|
||||
if res['code'] == 0
|
||||
@notice = "实训开启成功"
|
||||
elsif res['code'] == -2
|
||||
@notice = "Job已存在"
|
||||
else
|
||||
@notice = res['msg'].nil? ? "实训开启失败" : res['msg']
|
||||
end
|
||||
end
|
||||
|
||||
# TrainintTask.status 0:评测中 1:评测成功 2:评测惊醒中
|
||||
|
@ -871,17 +881,19 @@ class ProjectsController < ApplicationController
|
|||
params = {:jobName => "#{jobName}", :taskId => "#{taskId}"}
|
||||
uri = URI.parse("http://123.59.135.74:9999/jenkins-exec/api/buildJob")
|
||||
begin
|
||||
respond_message = uri_exec uri, params
|
||||
res = uri_exec uri, params
|
||||
# 任务开启成功后创建一条留言提示,并发布
|
||||
@training_task.update_attribute(:status, 2)
|
||||
return
|
||||
rescue
|
||||
@message = "失败,请联系系统管理员"
|
||||
rescue Exception => e
|
||||
puts e
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def uri_exec uri, params
|
||||
res = Net::HTTP.post_form(uri, params).body
|
||||
res = JSON.parse(res)
|
||||
end
|
||||
|
||||
# 开启实训项目,学生会fork一个项目并自动发送任务
|
||||
|
@ -914,24 +926,49 @@ class ProjectsController < ApplicationController
|
|||
# 需要传Task ID
|
||||
# 判断任务是否完成
|
||||
# 如果完成则发送下一个任务直到任务结束
|
||||
# TrainingTask.status 1 成功,2 失败
|
||||
# TrainingTask.status 1 成功,其它失败
|
||||
def training_task_status
|
||||
status = params[:code].to_i
|
||||
status = params[:status].to_i
|
||||
task_id = params[:taskId]
|
||||
stage = params[:stage].to_i
|
||||
@training_task = TrainingTask.find(task_id)
|
||||
original_project_id = Project.find(@training_task.project_id).try(:forked_from_project_id)
|
||||
original_project = Project.find(original_project_id)
|
||||
message = params[:msg].to_i
|
||||
begin
|
||||
@training_task = TrainingTask.find(task_id)
|
||||
original_project_id = Project.find(@training_task.project_id).try(:forked_from_project_id)
|
||||
original_project = Project.find(original_project_id)
|
||||
rescue
|
||||
return
|
||||
end
|
||||
original_tasks_count = original_project.training_tasks.count
|
||||
position = @training_task.try(:position) + 1
|
||||
# 测试,默认成功
|
||||
if position <= original_tasks_count
|
||||
# 继续下一个任务
|
||||
publish_training_tasks original_project_id, @training_task.project_id, position
|
||||
@training_task.update_attribute(:status, 1)
|
||||
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
|
||||
# 创建一条回复提醒
|
||||
content = "恭喜您通过测评"
|
||||
add_training_task_journal(content, original_project.user_id)
|
||||
end
|
||||
else
|
||||
content = "很遗憾,您没有通过该步"
|
||||
add_training_task_journal(content, original_project.user_id)
|
||||
end
|
||||
end
|
||||
|
||||
# 创建一条回复
|
||||
def add_training_task_journal content, user_id
|
||||
jour = Journal.new
|
||||
jour.user_id = user_id
|
||||
jour.notes = content
|
||||
jour.journalized = @training_task
|
||||
jour.save
|
||||
update_user_activity(@training_task.class, @training_task.id)
|
||||
update_forge_activity(@training_task.class, @training_task.id)
|
||||
end
|
||||
|
||||
# 实训开启成功后,发布第一个任务
|
||||
# REDO:失败后提醒用户,及相关处理
|
||||
def publish_training_tasks original_project_id, new_training_project_id, position
|
||||
|
|
Loading…
Reference in New Issue