Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions lib/roast/dsl/cog/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ module Roast
module DSL
class Cog
class Config
class ConfigError < Roast::Error; end

class InvalidConfigError < ConfigError; end

# Validate that the config instance has all required parameters set in an acceptable manner
#
# Inheriting cog should implement this for its config class if validation is desired.
#
#: () -> void
def validate!; end

#: Hash[Symbol, untyped]
attr_reader :values

Expand Down
1 change: 1 addition & 0 deletions lib/roast/dsl/config_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def config_for(cog_class, name = nil)
end.values.each { |cfg| config = config.merge(cfg) }
name_scoped_config = fetch_name_scoped_config(cog_class, name) unless name.nil?
config = config.merge(name_scoped_config) if name_scoped_config
config.validate!
config
end

Expand Down
17 changes: 12 additions & 5 deletions lib/roast/dsl/system_cogs/map.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ class Map < SystemCog
class Config < Cog::Config
#: (Integer) -> void
def parallel(value)
raise ArgumentError, "value must be >= 0" if value < 0

# treat 0 as unlimited parallelism
@values[:parallel] = value > 0 ? value : nil
end
Expand All @@ -24,9 +22,17 @@ def no_parallel!
@values[:parallel] = 1
end

def validate!
valid_parallel!
end

#: () -> Integer?
def max_parallel_tasks
@values.fetch(:parallel, 1)
def valid_parallel!
parallel = @values.fetch(:parallel, 1)
return if parallel.nil?
raise InvalidConfigError, "'parallel' must be >= 0 if specified" if parallel < 0

parallel
end
end

Expand Down Expand Up @@ -103,7 +109,8 @@ def create_map_system_cog(params, input_proc)
em
end

max_parallel_semaphore = Async::Semaphore.new(config.max_parallel_tasks) if config.max_parallel_tasks.present?
max_parallel_tasks = config.valid_parallel!
max_parallel_semaphore = Async::Semaphore.new(max_parallel_tasks) if max_parallel_tasks.present?
tasks = input.items.map.with_index do |item, index|
if max_parallel_semaphore
max_parallel_semaphore.async { create_and_run_execution_manager.call(item, index) }
Expand Down