lib/fasten/executor.rb in fasten-0.2.0 vs lib/fasten/executor.rb in fasten-0.4.0
- old
+ new
@@ -1,12 +1,15 @@
module Fasten
class Executor < Task
include Fasten::LogSupport
include Fasten::DAG
include Fasten::UI
+ include Fasten::LoadSave
+ include Fasten::Stats
def initialize(name: nil, workers: 8, worker_class: Fasten::Worker, fasten_dir: '.fasten')
+ setup_stats(name)
super name: name || "#{self.class} #{$PID}", workers: workers, pid: $PID, state: :IDLE, worker_class: worker_class, fasten_dir: fasten_dir
initialize_dag
self.worker_list = []
log_path = "#{fasten_dir}/log/executor/#{self.name}.log"
@@ -14,26 +17,30 @@
self.log_file = File.new(log_path, 'a')
Fasten.logger.reopen log_file
end
def perform
- log_ini self, running_stats
+ log_ini self, running_counters
self.state = :RUNNING
+ load_stats
run_ui do
perform_loop
end
- self.state = :IDLE
- log_fin self, running_stats
+ self.state = task_list.map(&:state).all?(:DONE) ? :DONE : :FAIL
+ log_fin self, running_counters
+
+ stats_add_entry(self, state, self)
+ save_stats
end
- def done_stats
+ def done_counters
"#{task_done_list.count}/#{task_list.count}"
end
- def running_stats
+ def running_counters
"#{task_done_list.count + task_running_list.count}/#{task_list.count}"
end
def perform_loop
loop do
@@ -66,10 +73,10 @@
task_running_list.delete task
update_task task
- log_fin task, done_stats
+ log_fin task, done_counters
end
end
def raise_error_in_failure
return unless tasks_failed?