Skip to content

Commit 7c3dc3d

Browse files
committed
Adds multi-threading to updater.rb.
1 parent 6b80f9a commit 7c3dc3d

File tree

3 files changed

+14
-103
lines changed

3 files changed

+14
-103
lines changed

blah.html.md.erb

-96
This file was deleted.

clone_all_repos

-1
This file was deleted.

updater.rb

+14-6
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,45 @@
33

44
require 'pp'
55
require 'yaml'
6+
# require 'open3'
67

78
# Add new books to this array, as necessary
89
@books = ['docs-book-cloudfoundry', 'docs-book-pcfservices', 'docs-book-pivotalcf', 'docs-book-runpivotal']
910
@modified_repos = []
1011
@repo_list = ["docs-layout-repo", "docs-utility-scripts"]
1112

12-
# Create a list of the book repositories to be cloned_or_updated, and send them to cloner/updater.
13+
# Create a list of the book repositories to be cloned_or_updated, send them to cloner/updater, and display the ignored modified repos.
1314
def gather_repos(books)
1415
books.map do |book|
1516
YAML.load(File.open(Dir.home + '/workspace/' + book + '/config.yml'))['sections'].each do |section|
1617
@repo_list.push(section['repository']['name'])
1718
end
1819
end
1920
reduced_list = reduce_list_for_current_work @repo_list
20-
clone_or_update reduced_list.uniq
21+
multithread_pipe reduced_list.uniq
22+
# clone_or_update reduced_list.uniq
2123
display_modified_repos @modified_repos
2224
end
2325

2426
# Removes repos with changes from @repo_list
2527
def reduce_list_for_current_work(working_repos_array)
2628
working_repos_array.reject! do |repo|
27-
repo && @modified_repos.push(repo) if `cd ~/workspace/#{repo.gsub(/\w*-?\w*\//,'')}; git status`.include?('modified')
29+
repo && @modified_repos.push(repo) if File.directory?(Dir.home + '/workspace/' + repo.gsub(/\w*-?\w*\//,'')) && `cd ~/workspace/#{repo.gsub(/\w*-?\w*\//,'')}; git status`.include?('modified')
2830
end
2931
working_repos_array.compact.uniq
3032
end
3133

34+
def multithread_pipe(list_of_repos)
35+
threads = []
36+
list_of_repos.each do |repo|
37+
threads << Thread.new { clone_or_update repo}
38+
end
39+
threads.each{|t|t.join}
40+
end
41+
3242
# Ternary operation that checks for directory existence, if none, clones; otherwise updates repo
33-
def clone_or_update(repo_list)
34-
repo_list.each do |repo|
43+
def clone_or_update(repo)
3544
File.directory?(Dir.home + '/workspace/' + repo.gsub(/\w*-?\w*\//,'')) ? update_repo(repo) : clone_repo(repo)
36-
end
3745
end
3846

3947
# Displays repos with modifications

0 commit comments

Comments
 (0)