Skip to content

Commit ca6a581

Browse files
committed
Only invoke parallel processing when needed
1 parent 7596075 commit ca6a581

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

lib/octocatalog-diff/cli.rb

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -123,17 +123,12 @@ def self.cli(argv = ARGV, logger = Logger.new(STDERR), opts = {})
123123
all_diffs = []
124124

125125
# run multiple node diffs in parallel
126-
Parallel.map(node_set, in_threads: 4) do |node|
127-
options[:node] = node
128-
catalog_diff = OctocatalogDiff::API::V1.catalog_diff(options.merge(logger: logger))
129-
diffs = catalog_diff.diffs
130-
131-
# Display diffs
132-
printer_obj = OctocatalogDiff::Cli::Printer.new(options, logger)
133-
printer_obj.printer(diffs, catalog_diff.from.compilation_dir, catalog_diff.to.compilation_dir)
134-
135-
# Append any diffs for final exit status
136-
all_diffs << diffs
126+
if node_set.size == 1
127+
all_diffs << run_octocatalog_diff(node_set.first, options, logger)
128+
else
129+
::Parallel.map(node_set, in_threads: 4) do |node|
130+
all_diffs << run_octocatalog_diff(node, options, logger)
131+
end
137132
end
138133

139134
# Return the resulting diff object if requested (generally for testing) or otherwise return exit code
@@ -147,6 +142,24 @@ def self.cli(argv = ARGV, logger = Logger.new(STDERR), opts = {})
147142
EXITCODE_SUCCESS_NO_DIFFS
148143
end
149144

145+
# Run the octocatalog-diff process for a given node. Return the diffs for a contribution to
146+
# the final exit status.
147+
# node - String with the node
148+
# options - All of the currently defined options
149+
# logger - Logger object
150+
def self.run_octocatalog_diff(node, options, logger)
151+
options_copy = options.merge(node: node)
152+
catalog_diff = OctocatalogDiff::API::V1.catalog_diff(options_copy.merge(logger: logger))
153+
diffs = catalog_diff.diffs
154+
155+
# Display diffs
156+
printer_obj = OctocatalogDiff::Cli::Printer.new(options_copy, logger)
157+
printer_obj.printer(diffs, catalog_diff.from.compilation_dir, catalog_diff.to.compilation_dir)
158+
159+
# Return diffs
160+
diffs
161+
end
162+
150163
# Parse command line options with 'optparse'. Returns a hash with the parsed arguments.
151164
# @param argv [Array] Command line arguments (MUST be specified)
152165
# @return [Hash] Options

0 commit comments

Comments
 (0)