Class: JFlow::Cli

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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(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

Instance Attribute Details

#activities_pathObject (readonly)

Returns the value of attribute activities_path.



11
12
13
# File 'lib/jflow/cli.rb', line 11

def activities_path
  @activities_path
end

#domainObject (readonly)

Returns the value of attribute domain.



11
12
13
# File 'lib/jflow/cli.rb', line 11

def domain
  @domain
end

#enable_statsObject (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_workersObject (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

#tasklistObject (readonly)

Returns the value of attribute tasklist.



11
12
13
# File 'lib/jflow/cli.rb', line 11

def tasklist
  @tasklist
end

#worker_threadsObject (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_workersObject

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_workersObject



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