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
# 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"]
  @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

#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.



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/jflow/cli.rb', line 43

def shutdown_workers
  log "Sending kill signal to running threads. Please wait for current polling to finish"
  kill_threads = []
  worker_threads.each do |thread|
    thread.mark_for_shutdown
    if thread.currently_working?
        kill_threads << kill_thread(thread)
    end
  end
  kill_threads.each(&:join)
end

#start_workersObject



23
24
25
26
27
28
# File 'lib/jflow/cli.rb', line 23

def start_workers
  number_of_workers.times do
    worker_threads << worker_thread
  end
  worker_threads.each(&:join)
end