Class: JFlow::Cli
- Inherits:
-
Object
- Object
- JFlow::Cli
- Defined in:
- lib/jflow/cli.rb
Constant Summary collapse
- VALIDATION =
{ "number_of_workers" => "integer", "domain" => "string", "tasklist" => "string", "activities_path" => "array" }
Instance Attribute Summary collapse
-
#activities_path ⇒ Object
readonly
Returns the value of attribute activities_path.
-
#domain ⇒ Object
readonly
Returns the value of attribute domain.
-
#enable_stats ⇒ Object
readonly
Returns the value of attribute enable_stats.
-
#number_of_workers ⇒ Object
readonly
Returns the value of attribute number_of_workers.
-
#tasklist ⇒ Object
readonly
Returns the value of attribute tasklist.
-
#worker_threads ⇒ Object
readonly
Returns the value of attribute worker_threads.
Instance Method Summary collapse
-
#initialize(options) ⇒ Cli
constructor
A new instance of Cli.
-
#shutdown_workers ⇒ Object
here we want to handle all cases for clean kill of the workers.
- #start_workers ⇒ Object
Constructor Details
#initialize(options) ⇒ Cli
Returns a new instance of Cli.
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/jflow/cli.rb', line 13 def initialize() () @number_of_workers = ["number_of_workers"] @domain = ["domain"] @tasklist = ["tasklist"] @activities_path = ["activities_path"] @enable_stats = ["enable_stats"] || true @worker_threads = [] setup end |
Instance Attribute Details
#activities_path ⇒ Object (readonly)
Returns the value of attribute activities_path.
11 12 13 |
# File 'lib/jflow/cli.rb', line 11 def activities_path @activities_path end |
#domain ⇒ Object (readonly)
Returns the value of attribute domain.
11 12 13 |
# File 'lib/jflow/cli.rb', line 11 def domain @domain end |
#enable_stats ⇒ Object (readonly)
Returns the value of attribute enable_stats.
11 12 13 |
# File 'lib/jflow/cli.rb', line 11 def enable_stats @enable_stats end |
#number_of_workers ⇒ Object (readonly)
Returns the value of attribute number_of_workers.
11 12 13 |
# File 'lib/jflow/cli.rb', line 11 def number_of_workers @number_of_workers end |
#tasklist ⇒ Object (readonly)
Returns the value of attribute tasklist.
11 12 13 |
# File 'lib/jflow/cli.rb', line 11 def tasklist @tasklist end |
#worker_threads ⇒ Object (readonly)
Returns the value of attribute worker_threads.
11 12 13 |
# File 'lib/jflow/cli.rb', line 11 def worker_threads @worker_threads end |
Instance Method Details
#shutdown_workers ⇒ Object
here we want to handle all cases for clean kill of the workers. there is two state on which the workers can be
-
Polling : they are not working on anything and are just waiting for a task
-
Working : they are processing an activity right now
for Polling, we cannot stop it in flight, so we send a signal to stop polling after the current long poll finishes, IF it picks up anything in the mean time the activity will be force failed
for Working, we give a grace period of 60 seconds to finish otherwise we just send an exception to the thread to force the failure.
Shutting down workers will take a exactly 60 secs in all cases.
45 46 47 48 49 50 51 52 53 |
# File 'lib/jflow/cli.rb', line 45 def shutdown_workers log "Sending kill signal to running threads. Please wait for current polling to finish" worker_threads.each do |thread| thread.mark_for_shutdown if thread.currently_working? && thread.alive? thread.raise("Workers are going down!") end end end |
#start_workers ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/jflow/cli.rb', line 24 def start_workers number_of_workers.times do worker_threads << worker_thread end worker_threads << maintenance_thread if enable_stats || is_ec2_instance? worker_threads.each(&:join) end |