File tree Expand file tree Collapse file tree 3 files changed +24
-5
lines changed Expand file tree Collapse file tree 3 files changed +24
-5
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,17 @@ module Roast
55 module DSL
66 class Cog
77 class Config
8+ class ConfigError < Roast ::Error ; end
9+
10+ class InvalidConfigError < ConfigError ; end
11+
12+ # Validate that the config instance has all required parameters set in an acceptable manner
13+ #
14+ # Inheriting cog should implement this for its config class if validation is desired.
15+ #
16+ #: () -> void
17+ def validate! ; end
18+
819 #: Hash[Symbol, untyped]
920 attr_reader :values
1021
Original file line number Diff line number Diff line change @@ -53,6 +53,7 @@ def config_for(cog_class, name = nil)
5353 end . values . each { |cfg | config = config . merge ( cfg ) }
5454 name_scoped_config = fetch_name_scoped_config ( cog_class , name ) unless name . nil?
5555 config = config . merge ( name_scoped_config ) if name_scoped_config
56+ config . validate!
5657 config
5758 end
5859
Original file line number Diff line number Diff line change @@ -8,8 +8,6 @@ class Map < SystemCog
88 class Config < Cog ::Config
99 #: (Integer) -> void
1010 def parallel ( value )
11- raise ArgumentError , "value must be >= 0" if value < 0
12-
1311 # treat 0 as unlimited parallelism
1412 @values [ :parallel ] = value > 0 ? value : nil
1513 end
@@ -24,9 +22,17 @@ def no_parallel!
2422 @values [ :parallel ] = 1
2523 end
2624
25+ def validate!
26+ valid_parallel!
27+ end
28+
2729 #: () -> Integer?
28- def max_parallel_tasks
29- @values . fetch ( :parallel , 1 )
30+ def valid_parallel!
31+ parallel = @values . fetch ( :parallel , 1 )
32+ return if parallel . nil?
33+ raise InvalidConfigError , "'parallel' must be >= 0 if specified" if parallel < 0
34+
35+ parallel
3036 end
3137 end
3238
@@ -103,7 +109,8 @@ def create_map_system_cog(params, input_proc)
103109 em
104110 end
105111
106- max_parallel_semaphore = Async ::Semaphore . new ( config . max_parallel_tasks ) if config . max_parallel_tasks . present?
112+ max_parallel_tasks = config . valid_parallel!
113+ max_parallel_semaphore = Async ::Semaphore . new ( max_parallel_tasks ) if max_parallel_tasks . present?
107114 tasks = input . items . map . with_index do |item , index |
108115 if max_parallel_semaphore
109116 max_parallel_semaphore . async { create_and_run_execution_manager . call ( item , index ) }
You can’t perform that action at this time.
0 commit comments