I have a rake task that uploads a list of files via ftp. Copying without threading works fine, but it would be faster if I could do multiple concurrent uploads. (I'm new to ruby and multithreading, so no surprise it didn't work right off the bat.)
I have:
files.each_slice(files.length / max_threads) do |file_set|
threads << Thread.new(file_set) do |file_slice|
running_threads += 1
thread_num = running_threads
thread_num.freeze
puts "making thread # #{thread_num}"
file_slice.each do |file|
file.freeze
if File.directory?(file)
else
puts file.pathmap("#{$ftpDestination}%p")
ftp.putbinaryfile(file, file.pathmap("#{$ftpDestination}%p"))
end
end
end
end
My output is:
making thread # 1
/test/./1column-ff-template.aspx
making thread # 2
making thread # 3
/test/./admin/footerContent.aspx
/test/./admin/contentList.aspx
making thread # 4
/test/./3columnTemplate.ascx
making thread # 5
/test/./ascx/dashboard/dash.ascx
making thread # 6
/test/./ascx/Links.ascx
making thread # 7
/test/./bin/App_GlobalResources.dll
making thread # 8
/test/./bin/App_Web__foxtqrr.dll
making thread # 9
/test/./GetPageLink.ascx
So it looks like each thread starts to upload a file and then dies without an error. What am I doing wrong?