添加实训评测任务

This commit is contained in:
huang 2017-06-13 16:03:38 +08:00
parent 3c0477c813
commit 74e2ef9429
5 changed files with 44 additions and 5 deletions

View File

@ -929,10 +929,10 @@ class ProjectsController < ApplicationController
end
end
def uri_exec uri, params
res = Net::HTTP.post_form(uri, params).body
res = JSON.parse(res)
end
# def uri_exec uri, params
# # res = Net::HTTP.post_form(uri, params).body
# # res = JSON.parse(res)
# end
# 开启实训项目,学生会fork一个项目并自动发送任务
def training_project_extend

View File

@ -268,7 +268,7 @@ module ApplicationHelper
res = JSON.parse(res)
rescue => e
logger.error("failed to create challenge by 'generatePipelineScriptForChallenge'! #{e}")
raise("实训云平台繁忙繁忙等级84")
raise("实训云平台繁忙繁忙等级84")
end
end

View File

@ -1,6 +1,7 @@
# status 控制实训的状态0未开启1: 已开启TPM; 2已认证
# 繁忙等级参数80发布实训失败返回code为-181实训开启的时候fork失败;83j 84jenkins系统异常post数据不成功
# 85challenge创建的时候Jenkins处理异常;86实训评测失败jenkins返回错误结果; 87版本库删除异常88点击评测失败没返回数据89重置链接jenkins返回失败
# 116challenge创建关卡的时候返回结果错误
class Shixun < ActiveRecord::Base
attr_accessible :description, :is_public, :name, :changeset_num, :status, :user_id, :gpid, :language, :identifier, :authentication, :myshixun_count, :propaedeutics

View File

@ -0,0 +1,38 @@
namespace :jenkins do
namespace :myshixun do
desc "ping ce"
task :game_build => :environment do
100.times do
puts "start"
game = Game.find_by_identifier('lhf7cyvjgmnq')
myshixun = game.myshixun
game_challenge = game.challenge
rep_identify = Repository.where(:myshixun_id => myshixun.id, :type => "Repository::Gitlab").first.try(:identifier)
gitlab_address = Redmine::Configuration['gitlab_address']
gitUrl = gitlab_address.to_s+"/"+myshixun.owner.to_s+"/"+ rep_identify + "."+"git"
gitUrl = Base64.encode64(gitUrl)
taskId = game.id
jobName = "myshixun_#{myshixun.id}"
if game.status == 2
game.update_attribute(:status, 0)
end
# 过关后重评不更新状态
jenkins_shixuns = Redmine::Configuration['jenkins_shixuns']
step = game_challenge.try(:position)
params = {:jobNameForInstance => "#{jobName}", :buildID => "#{taskId}", :step => "#{step}", :instanceGitURL => "#{gitUrl}", :instanceChallenge => "#{step}", :resubmit => nil}
uri = URI("#{jenkins_shixuns}/jenkins-exec/api/buildJobForInstance")
puts("post data time is #{Time.now}")
res = Net::HTTP.post_form(uri, params).body
res = JSON.parse(res)
puts("post data end time is #{Time.now}")
if (res && res['code'] != 0)
puts("error")
puts("current time is #{Time.now}")
end
puts("game over")
puts("waiting for 120s")
sleep(120);
end
end
end
end

View File