mirror of
https://github.com/System-End/highway.git
synced 2026-04-19 22:05:13 +00:00
Switch to thread pool for pulling projects
This commit is contained in:
parent
ab566301e1
commit
986a103e1e
1 changed files with 22 additions and 12 deletions
|
|
@ -3,26 +3,36 @@ class CloneProjectsJob < ApplicationJob
|
|||
|
||||
def perform
|
||||
submissions = YAML.load_file(Rails.root.join("submissions.yml"))
|
||||
|
||||
submissions["projects"].each do |url|
|
||||
urls = submissions["projects"].map do |url|
|
||||
url = url.chomp("/")
|
||||
url = "#{url}.git" unless url.end_with?(".git")
|
||||
url
|
||||
end
|
||||
|
||||
org, repo = url.gsub("https://github.com/", "").gsub(".git", "").split("/")
|
||||
org = org.downcase
|
||||
repo = repo.downcase
|
||||
queue = Queue.new
|
||||
urls.each { |url| queue << url }
|
||||
|
||||
target_dir = File.join(Rails.root, "content", "projects", org, repo)
|
||||
threads = 5.times.map do
|
||||
Thread.new do
|
||||
while url = queue.pop(true) rescue nil
|
||||
org, repo = url.gsub("https://github.com/", "").gsub(".git", "").split("/")
|
||||
org = org.downcase
|
||||
repo = repo.downcase
|
||||
target_dir = File.join(Rails.root, "content", "projects", org, repo)
|
||||
|
||||
if Dir.exist?(target_dir) && Dir.exist?(File.join(target_dir, ".git"))
|
||||
Rails.logger.info "Pulling latest for #{org}/#{repo}..."
|
||||
system("cd '#{target_dir}' && git pull")
|
||||
else
|
||||
Rails.logger.info "Cloning #{org}/#{repo}..."
|
||||
system("git clone #{url} '#{target_dir}'")
|
||||
if Dir.exist?(target_dir) && Dir.exist?(File.join(target_dir, ".git"))
|
||||
Rails.logger.info "Pulling latest for #{org}/#{repo}..."
|
||||
system("cd '#{target_dir}' && git pull")
|
||||
else
|
||||
Rails.logger.info "Cloning #{org}/#{repo}..."
|
||||
system("git clone #{url} '#{target_dir}'")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
threads.each(&:join)
|
||||
|
||||
Rails.logger.info "Done cloning and updating all projects!"
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue