Class: Eco::API::Session::Config::Workflow
- Extended by:
- Common::ClassHierarchy
- Defined in:
- lib/eco/api/session/config/workflow.rb
Constant Summary collapse
- WORKFLOW_MODEL =
:options, {load: [{input: %i[get filter]}, {data: %i[get filter]}, :filter]}, :usecases, :launch_jobs, {post_launch: %i[usecases launch_jobs]}, :report, :end, :close ].freeze
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Attributes included from Common::ClassHierarchy
Class Method Summary collapse
Instance Method Summary collapse
-
#after(key = nil) {|stage_workflow, io| ... } ⇒ Eco::API::Session::Config::Workflow
Used in configuration time add previous
callbacksafter theoncallback of the (sub)stagekeyis actuallyrun. -
#before(key = nil) {|stage_workflow, io| ... } ⇒ Eco::API::Session::Config::Workflow
Used in configuration time add previous
callbacksbefore theoncallback of the (sub)stagekeyis actuallyrun. -
#exit_handle(&block) ⇒ Object
Called on
SystemExitexception. -
#for(key = nil) {|stage_workflow| ... } ⇒ Eco::API::Session::Config::Workflow
(also: #with)
Used in configuration time to configure the workflow of the target (sub)stage
key. -
#initialize(name = nil, config:, _parent: self) ⇒ Workflow
constructor
rubocop:disable Lint/UnderscorePrefixedVariableName.
- #name(with_path: false) ⇒ Object
-
#on(key = nil) {|stage_workflow, io| ... } ⇒ Eco::API::Session::Config::Workflow
Used in configuration time to define the behaviour the target (sub)stage
key. -
#pending? ⇒ Boolean
Has this stage run yet?.
-
#rescue {|exception, io| ... } ⇒ Eco::API::Session::Config::Workflow
(also: #exception)
When there is an
Exception, you might have defined somecallbackto do something with it (i.e. register, email). -
#run(key = nil, io:) {|stage_workflow, io| ... } ⇒ Eco::API::Session::Config::Workflow
Used in run time to execute the workflow of the (sub)stage
key. -
#skip! ⇒ Object
Do not run this stage!.
-
#skip? ⇒ Boolean
Has this stage been marked as to be skipped.
Methods included from Common::ClassHierarchy
Methods included from Common::ClassHelpers
#class_resolver, #descendants, #descendants?, #inheritable_attrs, #inheritable_class_vars, #inherited, #instance_variable_name, #new_class, #resolve_class, #to_constant
Constructor Details
#initialize(name = nil, config:, _parent: self) ⇒ Workflow
rubocop:disable Lint/UnderscorePrefixedVariableName
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/eco/api/session/config/workflow.rb', line 47 def initialize(name = nil, config:, _parent: self) # rubocop:disable Lint/UnderscorePrefixedVariableName @config = config @name = name @stages = {} @_parent = _parent @pending = true # moments @on = nil @before = [] @after = [] end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
45 46 47 |
# File 'lib/eco/api/session/config/workflow.rb', line 45 def config @config end |
Class Method Details
.model ⇒ Object
24 25 26 |
# File 'lib/eco/api/session/config/workflow.rb', line 24 def model super || {} end |
.stages ⇒ Object
20 21 22 |
# File 'lib/eco/api/session/config/workflow.rb', line 20 def stages model_attrs end |
.validate_stage!(stage) ⇒ Object
28 29 30 31 32 33 |
# File 'lib/eco/api/session/config/workflow.rb', line 28 def validate_stage!(stage) return true if stages.include?(stage) msg = "Unknown Workflow stage '#{stage}'. Should be any of #{stages}" raise ArgumentError, msg end |
Instance Method Details
#after(key = nil) {|stage_workflow, io| ... } ⇒ Eco::API::Session::Config::Workflow
- it will not
yieldit immediately, but when the workflow reaches the target stage - in this case, you can define multiple
callbacks
Used in configuration time add previous callbacks after the on callback
of the (sub)stage key is actually run
207 208 209 210 211 212 213 214 215 216 217 218 |
# File 'lib/eco/api/session/config/workflow.rb', line 207 def after(key = nil, &block) msg = 'A block should be given.' raise ArgumentError, msg unless block_given? if key stage(key).after(&block) else @after.push(block) end self end |
#before(key = nil) {|stage_workflow, io| ... } ⇒ Eco::API::Session::Config::Workflow
- it will not
yieldit immediately, but when the workflow reaches the target stage - in this case, you can define multiple
callbacks
Used in configuration time add previous callbacks
before the on callback of the (sub)stage key is actually run
180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'lib/eco/api/session/config/workflow.rb', line 180 def before(key = nil, &block) msg = 'A block should be given.' raise ArgumentError, msg unless block_given? if key stage(key).before(&block) else @before.push(block) end self end |
#exit_handle(&block) ⇒ Object
Called on SystemExit exception
159 160 161 162 163 164 |
# File 'lib/eco/api/session/config/workflow.rb', line 159 def exit_handle(&block) return @exit_handle unless block_given? @exit_handle = block self end |
#for(key = nil) {|stage_workflow| ... } ⇒ Eco::API::Session::Config::Workflow Also known as: with
- if a
blockis provided it willyieldthe target stage immediately - a
blockis only required whenkeyhas not been specified.
Used in configuration time to configure the workflow of the target (sub)stage key
104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/eco/api/session/config/workflow.rb', line 104 def for(key = nil, &block) msg = "With no 'key', a block should be given." raise ArgumentError, msg unless key || block_given? tap do next yield(self) unless key next stage(key).for(&block) if block_given? return stage(key) end end |
#name(with_path: false) ⇒ Object
61 62 63 64 65 |
# File 'lib/eco/api/session/config/workflow.rb', line 61 def name(with_path: false) return @name if !with_path || root? [@_parent.name(with_path: true), @name].compact.join('.') end |
#on(key = nil) {|stage_workflow, io| ... } ⇒ Eco::API::Session::Config::Workflow
if a block is provided it will not yield the target stage immediately,
but when the workflow reaches the stage
Used in configuration time to define the behaviour the target (sub)stage key
128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/eco/api/session/config/workflow.rb', line 128 def on(key = nil, &block) msg = 'A block should be given.' raise ArgumentError, msg unless block_given? if key stage(key).on(&block) else @on = block end self end |
#pending? ⇒ Boolean
it does not include sub-stages that run before
Has this stage run yet?
70 71 72 |
# File 'lib/eco/api/session/config/workflow.rb', line 70 def pending? @pending end |
#rescue {|exception, io| ... } ⇒ Eco::API::Session::Config::Workflow Also known as: exception
When there is an Exception, you might have defined some callback
to do something with it (i.e. register, email)
149 150 151 152 153 154 |
# File 'lib/eco/api/session/config/workflow.rb', line 149 def rescue(&block) return @rescue unless block_given? @rescue = block self end |
#run(key = nil, io:) {|stage_workflow, io| ... } ⇒ Eco::API::Session::Config::Workflow
if a block is not provided:
- it will run the
beforecallbacks defined during the configuration time - it will run the workflow of any defined substage of the
keystage - it will run the
oncallback defined during the configuration time - it will mark the stage as not
pending?. - it will run the
aftercallbacks defined during the configuration time
if a block is provided:
- it will not run the workflow of the substages to
keystage - it will not run the
callbackforondefined during the configuration time - it will rather
yieldthe target stage after all thebeforecallbacks have been run - aside of this, the rest will be the same as when the block is provided (see previous note)
[if the object returned by before, after and run callbacks
is not an Eco::API::UseCases::BaseIO, the original io object will be returned instead.
Used in run time to execute the workflow of the (sub)stage key
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 |
# File 'lib/eco/api/session/config/workflow.rb', line 243 def run(key = nil, io:, &block) raise 'Missing BaseIO object' unless io.is_a?(Eco::API::UseCases::BaseIO) rescuable(io) do if key io = io_result(io: io) do stage(key).run(io: io, &block) end elsif pending? io = run_before(io) io = run_it(io, &block) unless skip? io = run_after(io) end io ensure @pending = false end end |
#skip! ⇒ Object
Do not run this stage!
75 76 77 78 |
# File 'lib/eco/api/session/config/workflow.rb', line 75 def skip! @skip = true @pending = false end |
#skip? ⇒ Boolean
Has this stage been marked as to be skipped
85 86 87 88 89 90 |
# File 'lib/eco/api/session/config/workflow.rb', line 85 def skip? return @skip if instance_variable_defined?(:@skip) return false if root? @_parent.skip? end |