lib/jflow/cli.rb in jflow-0.3.5 vs lib/jflow/cli.rb in jflow-0.3.6
- old
+ new
@@ -6,26 +6,28 @@
"domain" => "string",
"tasklist" => "string",
"activities_path" => "array"
}
- attr_reader :number_of_workers, :domain, :tasklist, :worker_threads, :activities_path
+ attr_reader :number_of_workers, :domain, :tasklist, :worker_threads, :activities_path, :enable_stats
def initialize(options)
validate_options(options)
@number_of_workers = options["number_of_workers"]
@domain = options["domain"]
@tasklist = options["tasklist"]
@activities_path = options["activities_path"]
+ @enable_stats = options["enable_stats"] || true
@worker_threads = []
setup
end
def start_workers
number_of_workers.times do
worker_threads << worker_thread
end
+ worker_threads << stats_thread if enable_stats
worker_threads.each(&:join)
end
# here we want to handle all cases for clean kill of the workers.
# there is two state on which the workers can be
@@ -56,11 +58,24 @@
def setup
JFlow.configure do |c|
c.load_paths = activities_path
c.swf_client = Aws::SWF::Client.new
+ c.cloudwatch_client = Aws::CloudWatch::Client.new
end
JFlow.load_activities
+ end
+
+ def stats_thread
+ JFlow::WorkerThread.new do
+ Thread.current.set_state(:polling)
+ stats = JFlow::Stats.new(@domain, @tasklist)
+ loop do
+ break if Thread.current.marked_for_shutdown?
+ stats.tick
+ sleep 30
+ end
+ end
end
def kill_thread(thread)
Thread.new do
sleep 60
\ No newline at end of file