Class: Paraduct::ParallelRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/paraduct/parallel_runner.rb

Class Method Summary collapse

Class Method Details

.perform_all(script, product_variables) ⇒ Paraduct::TestResponse

run script with arguments

Parameters:

  • script (String, Array<String>)

    script file, script(s)

  • product_variables (Array<Hash{String => String}>)

Returns:

Raises:



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/paraduct/parallel_runner.rb', line 9

def self.perform_all(script, product_variables)
  test_response = Paraduct::TestResponse.new
  base_job_dir = Paraduct.config.work_dir
  FileUtils.mkdir_p(base_job_dir) unless base_job_dir.exist?

  Paraduct.logger.info "======================================================\nSTART matrix test\n  EOS\n\n  pool = Thread.pool(Paraduct.config.max_threads)\n  begin\n    product_variables.each_with_index do |params, index|\n      runner = Paraduct::Runner.new(\n        script:       script,\n        params:       params,\n        base_job_dir: base_job_dir,\n        job_id:       index + 1,\n      )\n      pool.process do\n        runner.logger.info \"[START] params: \#{runner.formatted_params}\"\n        runner.setup_dir\n        begin\n          stdout = runner.perform\n          successful = true\n        rescue Paraduct::Errors::ProcessError => e\n          runner.logger.error \"exitstatus=\#{e.status}, \#{e.inspect}\"\n          stdout = e.message\n          successful = false\n\n        rescue Exception => e\n          runner.logger.error \"Unknown error: \#{e.inspect}\"\n          runner.logger.error e.backtrace.join(\"\\n\")\n          successful = false\n        end\n\n        runner.logger.info \"[END]   params: \#{runner.formatted_params}\"\n\n        test_response.jobs_push(\n          job_name:         runner.job_name,\n          params:           runner.params,\n          formatted_params: runner.formatted_params,\n          successful:       successful,\n          stdout:           stdout,\n        )\n      end\n    end\n  ensure\n    pool.shutdown\n  end\n\n  raise Paraduct::Errors::DirtyExitError unless test_response.jobs_count == product_variables.count\n\n  test_response\nend\n"