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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/ree_spec/packages/ree_spec_cli/package/ree_spec_cli/services/run_specs.rb', line 17
def call(package_names, spec_matcher, tag, files, run_all, only_failed, project_path, process_count)
init_ree_project(project_path)
packages = filter_packages_to_run(package_names, tag, run_all)
jobs, meta_index = get_jobs(packages, spec_matcher, files, only_failed)
processes = build_processes(process_count)
error_files = []
success_files = []
jobs.each do |job|
number = wait_for_vailable_process(processes)
error_file, success_file = Tempfile.new, Tempfile.new
error_files.push(error_file)
success_files.push(success_file)
processes[number] = Process.fork do
print_start_message(job)
prev_meta = meta_index[job.abs_path]
start_time = Time.now
result = run_package_specs(job.package, [job.abs_path], number)
end_time = Time.now
exec_time = end_time - start_time
is_success = result.status.exitstatus == 0
duration = if is_success
exec_time
elsif prev_meta
prev_meta.duration
else
exec_time
end
update_scan_metadata(
SpecMeta.new(
package: job.package.name.to_s,
abs_path: job.abs_path,
duration: duration,
last_scan_at: Time.now,
success: is_success
)
)
if !is_success
error_file.write(result.out)
error_file.rewind
puts(result.out)
else
success_file.write(result.out)
success_file.rewind
end
end
end
processes.each { |k, v| Process.wait(v) if !v.nil? }
print_messages(error_files, success_files)
nil
end
|