Added mock build. Part 4

This commit is contained in:
alexey
2025-03-12 23:44:22 +03:00
parent 9100c00397
commit 2059e19d0d
6 changed files with 90 additions and 8 deletions

View File

@@ -24,6 +24,9 @@ end
class ProjectsProjects < Sequel::Model(:projects_projects)
end
class BuildTask < Sequel::Model(:buildtask)
end
class DBase
attr :error, :last_id
@@ -216,4 +219,23 @@ class DBase
end
res
end
#result = 0 (in progress), 1 (stopped - error), 2 (stopped - success)
def create_build_task(prj_id, git_id, proj_path)
id = BuildTask.insert(repo_id: git_id.to_i, proj_id: prj_id.to_i, signpath: "", logpath: "", errlogpath: "", result: 0)
@last_id = id
BuildTask.where(id: id).update(logpath: File.join(proj_path, "#{id}"))
end
def update_build_task_status(build_id, status)
BuildTask.where(id: build_id.to_i).update(result: status.to_i)
end
def update_build_task_error_log(build_id, path)
BuildTask.where(id: build_id.to_i).update(errlogpath: path)
end
def get_build_task_process_log(build_id)
BuildTask.where(id: build_id.to_i).first
end
end

View File

@@ -1,14 +1,15 @@
require_relative "spork"
require_relative "runner"
require "fileutils"
#
#mock -r /home/alexey/workspace/ruby-projects/mock-gui/projects/prjt1.prj/configs/prjt1.cfg --buildsrpm --spec srcprp/bayrepo_neuro_farm.spec --sources srcprp/ --resultdir result/ --isolation=simple --disable-plugin=ccache
#mock -r /home/alexey/workspace/ruby-projects/mock-gui/projects/prjt1.prj/configs/prjt1.cfg result/bayrepo-neuro-farm-0.1-2.src.rpm --resultdir result2/ --isolation simple
class MockManager
attr :path, :config, :error, :last_status, :last_pid, :prep_dir, :db
attr :path, :config, :error, :last_status, :last_pid, :prep_dir, :db, :resultpath, :process_log, :repo_path
def initialize(path, config, cfg_counter_path, db)
def initialize(path, config, cfg_counter_path, db, result_path, repo_path)
@error = nil
unless File.exist? (path)
Dir.mkdir(path)
@@ -17,6 +18,8 @@ class MockManager
@config = config
cntr = 0
@db = db
@resultpath = result_path
@repo_path = repo_path
File.open(cfg_counter_path, "r+") do |f|
f.flock(File::LOCK_EX)
@@ -28,6 +31,20 @@ class MockManager
end
tmp_name = (0...10).map { ("a".."z").to_a[rand(26)] }.join
@prep_dir = File.join(path, "#{cntr}_#{tmp_name}")
pp @prep_dir
@process_log = File.join(@prep_dir, "process.log")
Dir.mkdir(@prep_dir)
FileUtils.touch(@process_log)
end
def get_build_process_log()
@process_log
end
def finalize_build_task()
FileUtils.rm_rf(@path)
end
def build_task()
finalize_build_task
end
end

View File

@@ -244,6 +244,7 @@ class ProjectsActions
end
def build_projects_git(prj_id, git_id, counter_file)
bld_id = 0
build_ok = true
proj_path = get_project_path(prj_id)
git_name = @db.get_repo_info_by_id(git_id)
@@ -256,6 +257,13 @@ class ProjectsActions
unless result
#Файл заблокирован считать id и вывести сведения о сборке
build_ok = false
build_id = f.gets.strip.to_i
if build_id > 0
build_info = @db.get_build_task_process_log(build_id)
unless build_info.nil?
bld_id = build_info[:id]
end
end
else
#Сборка завершилась, но каталог не подчистился
FileUtils.rm_rf(prepare_path)
@@ -272,9 +280,16 @@ class ProjectsActions
File.open(lockf_path, File::RDWR | File::CREAT) do |f|
f.flock(File::LOCK_EX)
#Начинаем сборку
mock = MockManager.new(prepare_path, get_project_config(prj_id), counter_file, @db)
FileUtils.rm_rf(prepare_path)
build_path = File.join(proj_path, PROJECTS_STRUCTURE[:LOGS], git_name[:reponame])
repo_path = File.join(proj_path, PROJECTS_STRUCTURE[:REPO])
@db.create_build_task(prj_id, git_id, build_path)
build_id = @db.last_id
mock = MockManager.new(prepare_path, get_project_config(prj_id), counter_file, @db, build_path, repo_path)
bld_id = build_id
@db.update_build_task_error_log(build_id, mock.get_build_process_log)
mock.build_task
end
end
bld_id
end
end