Class: Sicily::BatchProcessor
- Inherits:
-
Object
- Object
- Sicily::BatchProcessor
- Defined in:
- lib/sicily/batch_processor.rb
Instance Method Summary collapse
-
#initialize(files) ⇒ BatchProcessor
constructor
A new instance of BatchProcessor.
- #notify_beginning ⇒ Object
- #notify_done ⇒ Object
- #notify_done_when_finished ⇒ Object
- #process_added_file(file, &user_rule_block) ⇒ Object
- #process_each_file_in_thread(file, &user_rule_block) ⇒ Object
- #process_files_in_thread(&user_rule_block) ⇒ Object
- #run(&user_rule_block) ⇒ Object
Constructor Details
#initialize(files) ⇒ BatchProcessor
Returns a new instance of BatchProcessor.
9 10 11 12 13 |
# File 'lib/sicily/batch_processor.rb', line 9 def initialize(files) @files = files @pool = Concurrent::FixedThreadPool.new(Sicily.config.num_thread_pool) @latch = Concurrent::CountDownLatch.new(@files.size) end |
Instance Method Details
#notify_beginning ⇒ Object
23 24 25 |
# File 'lib/sicily/batch_processor.rb', line 23 def notify_beginning Util::NotificationUtil.notify_beginning(@files) end |
#notify_done ⇒ Object
55 56 57 |
# File 'lib/sicily/batch_processor.rb', line 55 def notify_done Util::NotificationUtil.notify_done(@files) end |
#notify_done_when_finished ⇒ Object
40 41 42 43 44 45 |
# File 'lib/sicily/batch_processor.rb', line 40 def notify_done_when_finished @pool.post do @latch.wait notify_done end end |
#process_added_file(file, &user_rule_block) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/sicily/batch_processor.rb', line 47 def process_added_file(file, &user_rule_block) file_processor = FileProcessor.new(file) file_processor.instance_eval(&user_rule_block) file_processor.info 'Done' rescue Exception => e Sicily.logger.error e.inspect end |
#process_each_file_in_thread(file, &user_rule_block) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/sicily/batch_processor.rb', line 33 def process_each_file_in_thread(file, &user_rule_block) @pool.post do process_added_file(file, &user_rule_block) @latch.count_down end end |
#process_files_in_thread(&user_rule_block) ⇒ Object
27 28 29 30 31 |
# File 'lib/sicily/batch_processor.rb', line 27 def process_files_in_thread(&user_rule_block) @files.each do |file| process_each_file_in_thread file, &user_rule_block end end |
#run(&user_rule_block) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/sicily/batch_processor.rb', line 15 def run(&user_rule_block) return if @files.empty? notify_beginning process_files_in_thread(&user_rule_block) notify_done_when_finished end |