lib/fasten/runner.rb in fasten-0.14.2 vs lib/fasten/runner.rb in fasten-0.14.4

- old
+ new

@@ -35,11 +35,10 @@ %i[name stats summary jobs worker_class fasten_dir use_threads ui_mode developer priority].each do |key| send "#{key}=", options[key] if options.key? key end initialize_stats - initialize_logger end def task(name, **opts, &block) tasks << task = Task.new(name: name, **opts, block: block) @@ -49,10 +48,12 @@ def register(&block) instance_eval(&block) end def perform + initialize_logger + StdThreadProxy.install if use_threads self.state = :RUNNING log_ini self, running_counters load_stats touch_task_logs @@ -65,10 +66,12 @@ stats_add_entry(state, self) stats_summary if summary ensure + StdThreadProxy.uninstall if use_threads + close_logger save_stats end def touch_task_logs FileUtils.mkdir_p "#{fasten_dir}/log/task/" @@ -226,10 +229,10 @@ end end end def find_or_create_worker(worker_class:) - worker = workers.find { |item| item.class == worker_class && item.running_task.nil? } + worker = workers.find { |item| item.instance_of?(worker_class) && item.running_task.nil? } unless worker @worker_id = (@worker_id || 0) + 1 worker = worker_class.new runner: self, name: "#{worker_class.to_s.gsub('::', '-')}-#{format '%02X', @worker_id}", use_threads: use_threads worker.start