From ddb4003e662e7dd313460c7dc76b3a0465b744fa Mon Sep 17 00:00:00 2001 From: Jeff Yates Date: Sat, 21 Nov 2020 19:11:29 -0500 Subject: [PATCH] added threading to file processing --- sorter.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/sorter.rb b/sorter.rb index 09f9826..0ca54f1 100755 --- a/sorter.rb +++ b/sorter.rb @@ -148,7 +148,7 @@ def process_file (file_name, binfile, type) sections.delete_at(0) #we can ignore the first chunk of text sections.each do |chunk| timestamp = chunk.lines.delete_if {|line| line == "\r\n"}[0] #pulling out the timestamp - timestamp.tr!('/','-').tr!(':','').tr!(' ','_') #remove slashes and colons from timestamp, replaces spaces with unserscores + timestamp.tr!('/','-').tr!(':','').tr!(' ','_') #remove slashes and colons from timestamp, replaces spaces with underscores timestamp.strip! output = Hash.new #Creating the output storage object outfile = file_name + '_' + timestamp @@ -176,10 +176,14 @@ end # #This method will process all .txt files in the supplied directory def process_dir(dir_name, binfile, type) + threads = [] Dir.glob(dir_name + '*.txt') do |file_name| - puts "Processing " + file_name - process_file(file_name, binfile, type) + threads << Thread.new do + puts "Processing " + file_name + process_file(file_name, binfile, type) + end end + threads.each { |thr| thr.join } end def generate_master_output(dir_name, binfile)