修改chain命令及返回内容

This commit is contained in:
sylor_huang@126.com 2020-05-13 15:44:55 +08:00
parent d6d333d3e2
commit e3d0904e2c
3 changed files with 19 additions and 12 deletions

View File

@ -9,7 +9,8 @@ class ChangeTokenJob < ApplicationJob
break break
else else
Rails.logger.info("########_change_user_toke_try:_#{i+1}_") Rails.logger.info("########_change_user_toke_try:_#{i+1}_")
chain_status = system("chain #{change_params[:change_type]} #{change_params[:ownername]} #{change_params[:reponame]} #{change_params[:username]} #{change_params[:tokens].to_i}") chain_status = `chain #{change_params[:change_type]} #{change_params[:ownername]} #{change_params[:reponame]} #{change_params[:username]} #{change_params[:tokens].to_i}`
chain_status = eval(chain_status)
status = chain_status[:status].to_i status = chain_status[:status].to_i
end end
end end

View File

@ -5,7 +5,6 @@ class ProjectCreateChainJob < ApplicationJob
status = false status = false
chain_type = chain_params[:type].to_s chain_type = chain_params[:type].to_s
reponame = chain_params[:reponame] reponame = chain_params[:reponame]
Rails.logger.info("########_chain_params:________#{chain_params}")
5.times do |i| 5.times do |i|
if status if status
@ -14,15 +13,20 @@ class ProjectCreateChainJob < ApplicationJob
else else
Rails.logger.info("########_repository__#{reponame}______start_to_create_chain__try:_#{i+1}_") Rails.logger.info("########_repository__#{reponame}______start_to_create_chain__try:_#{i+1}_")
if chain_type == "create" if chain_type == "create"
status = create_chain(chain_params) chain_status = create_chain(chain_params)
elsif chain_type == "push" elsif chain_type == "push"
status = push_chain(chain_params) chain_status = push_chain(chain_params)
else
chain_status = {status: 200}
end end
Rails.logger.info("########_response__chain_status__#{chain_status}__")
status = chain_status[:status].to_i
end end
end end
unless status unless status == 200
Rails.logger.info("########_repository__#{reponame}__create_chain:___#{status}____failed_to_create_chain__") Rails.logger.info("########_repository__#{reponame}__create_chain:___#{chain_status}____failed_to_create_chain__")
end end
end end
@ -30,11 +34,13 @@ class ProjectCreateChainJob < ApplicationJob
#创建项目的上链操作 #创建项目的上链操作
def create_chain(chain_params) def create_chain(chain_params)
return system("chain trustieCreate #{chain_params[:ownername]} #{chain_params[:reponame]}") result = `chain trustieCreate #{chain_params[:ownername]} #{chain_params[:reponame]}`
return eval(result)
end end
# push项目的上链操作 # push项目的上链操作
def push_chain(chain_params) def push_chain(chain_params)
return system("chain trustiePush #{chain_params[:ownername]} #{chain_params[:reponame]} #{chain_params[:username]} #{chain_params[:uploadPushInfo]}") result = `chain trustiePush #{chain_params[:ownername]} #{chain_params[:reponame]} #{chain_params[:username]} #{chain_params[:uploadPushInfo]}`
return eval(result)
end end
end end

View File

@ -15,18 +15,18 @@ class Gitea::Repository::Hooks::QueryService < Gitea::ClientService
def call def call
query_type = query_params[:type] || "user" query_type = query_params[:type] || "user"
if query_type == "user" #查询单个用户的积分 if query_type == "user" #查询单个用户的积分
query_result = system("chain query #{query_params[:ownername]} #{query_params[:reponame]} #{query_params[:username]}") query_result = `chain query #{query_params[:ownername]} #{query_params[:reponame]} #{query_params[:username]}`
#response {status:int, message:string, value:int} #response {status:int, message:string, value:int}
elsif query_type == "members" #查询项目全部用户的积分 elsif query_type == "members" #查询项目全部用户的积分
query_result = system("chain getAllInfo #{query_params[:ownername]} #{query_params[:reponame]} ") query_result = `chain getAllInfo #{query_params[:ownername]} #{query_params[:reponame]}`
#response {status:int, message:string, value:jsonObject} #response {status:int, message:string, value:jsonObject}
else #查询用户在项目的贡献大小 else #查询用户在项目的贡献大小
query_result = system("chain getContributionPercent #{query_params[:ownername]} #{query_params[:reponame]} #{query_params[:username]}") query_result = `chain getContributionPercent #{query_params[:ownername]} #{query_params[:reponame]} #{query_params[:username]}`
#response {status:int, message:string, percent:int, allTokenSum:int, personalTokens:int} #response {status:int, message:string, percent:int, allTokenSum:int, personalTokens:int}
end end
query_result eval(query_result)
end end
end end