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.



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

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.



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

def auto_serialize=(value)
  @auto_serialize = value
end

#exit_statusesObject (readonly)

Returns the value of attribute exit_statuses.



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

def exit_statuses
  @exit_statuses
end

#hostsObject (readonly)

Returns the value of attribute hosts.



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

def hosts
  @hosts
end

#messagesObject (readonly)

Returns the value of attribute messages.



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

def messages
  @messages
end

#parallel_jobsObject (readonly)

Returns the value of attribute parallel_jobs.



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

def parallel_jobs
  @parallel_jobs
end

#taskObject (readonly)

Returns the value of attribute task.



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

def task
  @task
end

Instance Method Details

#runObject



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

def run
  if parallel_jobs > 1 && hosts.count > 1
    run_in_parallel
  else
    run_serially
  end
  report.print_full
end

#run_in_parallelObject



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

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



32
33
34
35
36
37
# File 'lib/dplyr/task_runner.rb', line 32

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