Class: Dplyr::TaskRunner

Inherits:
Object
  • Object
show all
Includes:
Dply::Logger
Defined in:
lib/dplyr/task_runner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Dply::Logger

#debug?, #logger, stderr, #stderr

Constructor Details

#initialize(hosts, task, parallel_jobs: 1) ⇒ TaskRunner

Returns a new instance of TaskRunner.



14
15
16
17
18
19
20
21
22
# File 'lib/dplyr/task_runner.rb', line 14

def initialize(hosts, task, parallel_jobs: 1)
  @hosts = hosts
  @parallel_jobs = parallel_jobs
  @task = task

  @messages = {}
  @exit_statuses = {}
  @auto_serialize = true
end

Instance Attribute Details

#auto_serialize=(value) ⇒ Object (writeonly)

Sets the attribute auto_serialize

Parameters:

  • value

    the value to set the attribute auto_serialize to.



12
13
14
# File 'lib/dplyr/task_runner.rb', line 12

def auto_serialize=(value)
  @auto_serialize = value
end

#exit_statusesObject (readonly)

Returns the value of attribute exit_statuses.



11
12
13
# File 'lib/dplyr/task_runner.rb', line 11

def exit_statuses
  @exit_statuses
end

#hostsObject (readonly)

Returns the value of attribute hosts.



11
12
13
# File 'lib/dplyr/task_runner.rb', line 11

def hosts
  @hosts
end

#messagesObject (readonly)

Returns the value of attribute messages.



11
12
13
# File 'lib/dplyr/task_runner.rb', line 11

def messages
  @messages
end

#parallel_jobsObject (readonly)

Returns the value of attribute parallel_jobs.



11
12
13
# File 'lib/dplyr/task_runner.rb', line 11

def parallel_jobs
  @parallel_jobs
end

#taskObject (readonly)

Returns the value of attribute task.



11
12
13
# File 'lib/dplyr/task_runner.rb', line 11

def task
  @task
end

Instance Method Details

#runObject

Raises:



24
25
26
27
28
29
30
31
32
# File 'lib/dplyr/task_runner.rb', line 24

def run
  raise ::Dply::Error, "no hosts found" if hosts.empty?
  if parallel_jobs > 1 && hosts.count > 1
    run_in_parallel
  else
    run_serially
  end
  report.print_full
end

#run_in_parallelObject



41
42
43
44
45
46
47
48
49
# File 'lib/dplyr/task_runner.rb', line 41

def run_in_parallel
  if @auto_serialize
    t = execute_serially hosts[0]
    return if t.exit_status != 0
    execute_in_parallel Range.new(1,hosts.size - 1)
  else
    execute_in_parallel Range.new(0, hosts.size - 1)
  end
end

#run_seriallyObject



34
35
36
37
38
39
# File 'lib/dplyr/task_runner.rb', line 34

def run_serially
  hosts.each do |host|
    task = execute_serially host
    break if task.exit_status != 0 
  end
end