Class: Ruote::Exp::FlowExpression
- Inherits:
-
Object
- Object
- Ruote::Exp::FlowExpression
- Includes:
- WithH, WithMeta
- Defined in:
- lib/ruote/exp/ro_persist.rb,
lib/ruote/exp/ro_variables.rb,
lib/ruote/exp/ro_attributes.rb,
lib/ruote/exp/flowexpression.rb
Overview
Ruote is a process definition interpreter. It doesn't directly “read” process definitions, it relies on a parser/generator to produce “abstract syntax trees” that look like
[ expression_name, { ... attributes ... }, [ children_expressions ] ]
The nodes (and leaves) in the trees are expressions. This is the base class for all expressions.
The most visible expressions are “define”, “sequence” and “participant”. Think :
pdef = Ruote.process_definition do
sequence do
participant :ref => 'customer'
participant :ref => 'accounting'
participant :ref => 'logistics'
end
end
Each node is an expression…
Direct Known Subclasses
AddBranchesExpression, ApplyExpression, CancelProcessExpression, CommandExpression, CommandedExpression, ConcurrenceExpression, CronExpression, DefineExpression, EchoExpression, EqualsExpression, ErrorExpression, FilterExpression, ForgetExpression, IfExpression, ListenExpression, LoseExpression, NoOpExpression, OnceExpression, ParticipantExpression, RedoExpression, RefExpression, RegisterpExpression, ReserveExpression, RestoreExpression, SaveExpression, SequenceExpression, SetExpression, SubprocessExpression, UndoExpression, WaitExpression
Constant Summary
- COMMON_ATT_KEYS =
%w[ if unless forget timeout on_error on_cancel on_timeout ]
Instance Attribute Summary (collapse)
-
- (Object) context
readonly
Returns the value of attribute context.
-
- (Object) h
Returns the value of attribute h.
Class Method Summary (collapse)
-
+ (Object) do_action(context, msg)
– apply/reply ++.
-
+ (Object) fetch(context, fei)
Fetches an expression from the storage and readies it for service.
-
+ (Object) from_h(context, h)
Instantiates expression back from hash.
-
+ (Object) names(*exp_names)
Keeping track of names and aliases for the expression.
Instance Method Summary (collapse)
-
- (Boolean) ancestor?(fei)
Returns true if the given fei points to an expression in the parent chain of this expression.
-
- (Object) att(key, values, opts = {})
Returns the value for attribute 'key', this value should be present in the array list 'values'.
-
- (Object) attribute(n, workitem = h.applied_workitem, options = {})
Looks up the value for attribute n.
-
- (Object) attribute_text(workitem = h.applied_workitem)
Given something like.
- - (Object) attributes
-
- (Object) cancel(flavour)
This default implementation cancels all the [registered] children of this expression.
-
- (Object) compile_atts(opts = {})
Returns a Hash containing all attributes set for an expression with their values resolved.
-
- (Object) compile_variables
Returns a fresh hash of all the variables visible from this expression.
- - (Object) do_apply
-
- (Object) do_cancel(msg)
The raw handling of messages passed to expressions (the fine handling is done in the #cancel method).
- - (Object) do_fail(msg)
- - (Object) do_persist
- - (Object) do_reply(msg) (also: #do_receive)
- - (Object) do_unpersist
-
- (Object) expand_atts(opts = {})
Like compile_atts, but the keys are expanded as well.
- - (Object) fei
-
- (Object) handle_on_error(msg, error)
Looks up parent with on_error attribute and triggers it.
-
- (Object) has_attribute(*args)
(also: #has_att)
Given a list of attribute names, returns the first attribute name for which there is a value.
-
- (Object) initial_persist
Persists and fetches the _rev identifier from the storage.
-
- (FlowExpression) initialize(context, h)
constructor
A new instance of FlowExpression.
-
- (Object) iterative_var_lookup(k)
TODO : redoc rewrite needed.
-
- (Object) launch_sub(pos, subtree, opts = {})
– misc ++.
-
- (Object) lookup_on_error
Looks up “on_error” attribute.
- - (Object) lookup_val(att_options = {})
-
- (Object) lookup_val_prefix(prefix, att_options = {})
prefix = 'on' => will lookup on, on_val, on_value, on_v, on_var, on_variable, on_f, on_fld, on_field…
-
- (Object) lookup_variable(var, prefix = nil)
(also: #v, #lv)
Looks up the value of a variable in expression tree (seen from a leaf, it looks more like a stack than a tree).
- - (Object) name
- - (Object) parent
- - (Object) parent_id
-
- (Object) persist_or_raise
(also: #persist)
– duplication ahead ++.
-
- (Object) reply(workitem)
A default implementation for all the expressions.
- - (Object) reply_to_parent(workitem, delete = true)
-
- (Object) set_variable(var, val)
Sets a variable to a given value.
-
- (Object) to_h
Turns this FlowExpression instance into a Hash (well, just hands back the base hash behind it).
-
- (Object) tree
Returns the current version of the tree (returns the updated version if it got updated..
- - (Object) tree_children
- - (Object) try_persist
- - (Object) try_unpersist
- - (Object) unpersist_or_raise (also: #unpersist)
-
- (Object) unset_variable(var)
Unbinds a variables.
-
- (Object) update_tree(t = nil)
Updates the tree of this expression.
-
- (Object) variables
A shortcut to the variables held in the expression (nil if none held).
Methods included from WithMeta
Methods included from WithH
Constructor Details
- (FlowExpression) initialize(context, h)
A new instance of FlowExpression
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/ruote/exp/flowexpression.rb', line 82 def initialize(context, h) @context = context @msg = nil self.h = h h._id ||= Ruote.to_storage_id(h.fei) h['type'] ||= 'expressions' h.name ||= self.class.expression_names.first h.children ||= [] h.applied_workitem['fei'] = h.fei h.created_time ||= Ruote.now_to_utc_s h.on_cancel ||= attribute(:on_cancel) h.on_error ||= attribute(:on_error) h.on_timeout ||= attribute(:on_timeout) end |
Instance Attribute Details
- (Object) context (readonly)
Returns the value of attribute context
67 68 69 |
# File 'lib/ruote/exp/flowexpression.rb', line 67 def context @context end |
- (Object) h
Returns the value of attribute h
68 69 70 |
# File 'lib/ruote/exp/flowexpression.rb', line 68 def h @h end |
Class Method Details
+ (Object) do_action(context, msg)
– apply/reply ++
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/ruote/exp/flowexpression.rb', line 165 def self.do_action(context, msg) fei = msg['fei'] action = msg['action'] if action == 'reply' && fei['engine_id'] != context.engine_id # # the reply has to go to another engine, let's locate the # 'engine participant' and give it the workitem/reply # # see ft_37 for a test/example engine_participant = context.plist.lookup(fei['engine_id'], msg['workitem']) raise( "no EngineParticipant found under name '#{fei['engine_id']}'" ) unless engine_participant engine_participant.reply(fei, msg['workitem']) return end # normal case fexp = nil 3.times do fexp = fetch(context, msg['fei']) break if fexp sleep 0.028 end # this retry system is only useful with ruote-couch fexp.send("do_#{action}", msg) if fexp end |
+ (Object) fetch(context, fei)
Fetches an expression from the storage and readies it for service.
140 141 142 143 144 145 146 147 |
# File 'lib/ruote/exp/flowexpression.rb', line 140 def self.fetch(context, fei) return nil if fei.nil? fexp = context.storage.get('expressions', Ruote.to_storage_id(fei)) fexp ? from_h(context, fexp) : nil end |
+ (Object) from_h(context, h)
Instantiates expression back from hash.
131 132 133 134 135 136 |
# File 'lib/ruote/exp/flowexpression.rb', line 131 def self.from_h(context, h) exp_class = context.expmap.expression_class(h['name']) exp_class.new(context, h) end |
+ (Object) names(*exp_names)
Keeping track of names and aliases for the expression
155 156 157 158 159 |
# File 'lib/ruote/exp/flowexpression.rb', line 155 def self.names(*exp_names) exp_names = exp_names.collect { |n| n.to_s } (:expression_names) { exp_names } end |
Instance Method Details
- (Boolean) ancestor?(fei)
Returns true if the given fei points to an expression in the parent chain of this expression.
481 482 483 484 485 486 487 |
# File 'lib/ruote/exp/flowexpression.rb', line 481 def ancestor?(fei) return false unless h.parent_id return true if h.parent_id == fei parent.ancestor?(fei) end |
- (Object) att(key, values, opts = {})
Returns the value for attribute 'key', this value should be present in the array list 'values'. If not, the default value is returned. By default, the default value is the first element of 'values'.
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/ruote/exp/ro_attributes.rb', line 75 def att(key, values, opts={}) default = opts[:default] || values.first val = attribute(key) val = val.to_s if val #raise( # ArgumentError.new("attribute '#{key}' missing in #{tree}") #) if opts[:mandatory] && val == nil #raise( # ArgumentError.new("attribute '#{key}' has invalid value in #{tree}") #) if opts[:enforce] && (not values.include?(val)) values.include?(val) ? val : default end |
- (Object) attribute(n, workitem = h.applied_workitem, options = {})
Looks up the value for attribute n.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/ruote/exp/ro_attributes.rb', line 48 def attribute(n, workitem=h.applied_workitem, ={}) n = n.to_s default = [:default] escape = [:escape] string = [:to_s] || [:string] v = attributes[n] v = if v == nil default elsif escape v else @context.dollar_sub.s(v, self, workitem) end v = v.to_s if v and string v end |
- (Object) attribute_text(workitem = h.applied_workitem)
Given something like
sequence do
participant 'alpha'
end
in the context of the participant expression
attribute_text()
will yield 'alpha'.
Note : an empty text returns '', not the nil value.
153 154 155 156 157 158 |
# File 'lib/ruote/exp/ro_attributes.rb', line 153 def attribute_text(workitem=h.applied_workitem) text = attributes.keys.find { |k| attributes[k] == nil } @context.dollar_sub.s(text.to_s, self, workitem) end |
- (Object) attributes
589 590 591 |
# File 'lib/ruote/exp/flowexpression.rb', line 589 def attributes tree[1] end |
- (Object) cancel(flavour)
This default implementation cancels all the [registered] children of this expression.
388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 |
# File 'lib/ruote/exp/flowexpression.rb', line 388 def cancel(flavour) return reply_to_parent(h.applied_workitem) if h.children.empty? # # there are no children, nothing to cancel, let's just reply to # the parent expression do_persist || return # # before firing the cancel message to the children # # if the do_persist returns false, it means it failed, implying this # expression is stale, let's return, thus discarding this cancel message children.each do |cfei| # # let's send a cancel message to each of the children # # maybe some of them are gone or have not yet been applied, anyway, # the message are sent @context.storage.put_msg( 'cancel', 'fei' => cfei, 'parent_id' => h.fei, # indicating that this is a "cancel child" 'flavour' => flavour) end #if ! children.find { |i| Ruote::Exp::FlowExpression.fetch(@context, i) } # # # # since none of the children could be found in the storage right now, # # it could mean that all children are already done or it could mean # # that they are not yet applied... # # # # just to be sure let's send a new cancel message to this expression # # # # it's very important, since if there is no child to cancel the parent # # the flow might get stuck here # @context.storage.put_msg( # 'cancel', # 'fei' => h.fei, # 'flavour' => flavour) #end end |
- (Object) compile_atts(opts = {})
Returns a Hash containing all attributes set for an expression with their values resolved.
116 117 118 119 120 121 122 |
# File 'lib/ruote/exp/ro_attributes.rb', line 116 def compile_atts(opts={}) attributes.keys.inject({}) { |r, k| r[k] = attribute(k, h.applied_workitem, opts) r } end |
- (Object) compile_variables
Returns a fresh hash of all the variables visible from this expression.
This is used mainly when forgetting an expression.
44 45 46 47 48 49 50 |
# File 'lib/ruote/exp/ro_variables.rb', line 44 def compile_variables vars = h.parent_id ? parent.compile_variables : {} vars.merge!(h.variables) if h.variables vars end |
- (Object) do_apply
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 |
# File 'lib/ruote/exp/flowexpression.rb', line 202 def do_apply if not Condition.apply?(attribute(:if), attribute(:unless)) return reply_to_parent(h.applied_workitem) end if attribute(:forget).to_s == 'true' i = h.parent_id wi = Ruote.fulldup(h.applied_workitem) h.variables = compile_variables h.parent_id = nil h.forgotten = true @context.storage.put_msg('reply', 'fei' => i, 'workitem' => wi) elsif attribute(:lose).to_s == 'true' h.lost = true end consider_tag consider_timeout apply end |
- (Object) do_cancel(msg)
The raw handling of messages passed to expressions (the fine handling is done in the #cancel method).
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 |
# File 'lib/ruote/exp/flowexpression.rb', line 339 def do_cancel(msg) flavour = msg['flavour'] return if h.state == 'cancelling' && flavour != 'kill' # cancel on cancel gets discarded return if h.state == 'failed' && flavour == 'timeout' # do not timeout expressions that are "in error" (failed) @msg = Ruote.fulldup(msg) h.state = case flavour when 'kill' then 'dying' when 'timeout' then 'timing_out' else 'cancelling' end h.applied_workitem['fields']['__timed_out__'] = [ h.fei, Ruote.now_to_utc_s ] if h.state == 'timing_out' if h.state == 'cancelling' if t = msg['on_cancel'] h.on_cancel = t elsif hra = msg['re_apply'] hra = {} if hra == true h.on_re_apply = hra['tree'] || tree if fs = hra['fields'] h.applied_workitem['fields'] = fs end if mfs = hra['merge_in_fields'] h.applied_workitem['fields'].merge!(mfs) end end end cancel(flavour) end |
- (Object) do_fail(msg)
433 434 435 436 437 438 439 440 441 442 443 444 |
# File 'lib/ruote/exp/flowexpression.rb', line 433 def do_fail(msg) @h['state'] = 'failing' @h['applied_workitem'] = msg['workitem'] if h.children.size < 1 reply_to_parent(@h['applied_workitem']) else persist_or_raise h.children.each { |i| @context.storage.put_msg('cancel', 'fei' => i) } end end |
- (Object) do_persist
112 113 114 115 |
# File 'lib/ruote/exp/ro_persist.rb', line 112 def do_persist do_p(:persist) end |
- (Object) do_reply(msg) Also known as: do_receive
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 |
# File 'lib/ruote/exp/flowexpression.rb', line 294 def do_reply(msg) @msg = Ruote.fulldup(msg) # keeping the message, for 'retry' in collision cases workitem = msg['workitem'] fei = workitem['fei'] if ut = msg['updated_tree'] ct = tree.dup ct.last[Ruote::FlowExpressionId.child_id(fei)] = ut update_tree(ct) end h.children.delete(fei) # accept without any check ? if h.state != nil # failing or timing out ... if h.children.size < 1 reply_to_parent(workitem) else persist_or_raise # for the updated h.children end else # vanilla reply reply(workitem) end end |
- (Object) do_unpersist
117 118 119 120 |
# File 'lib/ruote/exp/ro_persist.rb', line 117 def do_unpersist do_p(:unpersist) end |
- (Object) expand_atts(opts = {})
Like compile_atts, but the keys are expanded as well.
Useful for things like
set "f:${v:field_name}" => "${v:that_variable}"
130 131 132 133 134 135 136 137 |
# File 'lib/ruote/exp/ro_attributes.rb', line 130 def (opts={}) attributes.keys.inject({}) { |r, k| kk = @context.dollar_sub.s(k, self, h.applied_workitem) r[kk] = attribute(k, h.applied_workitem, opts) r } end |
- (Object) fei
109 110 111 |
# File 'lib/ruote/exp/flowexpression.rb', line 109 def fei Ruote::FlowExpressionId.new(h.fei) end |
- (Object) handle_on_error(msg, error)
Looks up parent with on_error attribute and triggers it
522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 |
# File 'lib/ruote/exp/flowexpression.rb', line 522 def handle_on_error(msg, error) return false if h.state == 'failing' oe_parent = lookup_on_error return false unless oe_parent # no parent with on_error attribute found handler = oe_parent.on_error.to_s return false if handler == '' # empty on_error handler nullifies ancestor's on_error workitem = msg['workitem'] workitem['fields']['__error__'] = { 'fei' => fei, 'at' => Ruote.now_to_utc_s, 'class' => error.class.to_s, 'message' => error., 'trace' => error.backtrace } @context.storage.put_msg( 'fail', 'fei' => oe_parent.h.fei, 'workitem' => workitem) true # yes, error is being handled. end |
- (Object) has_attribute(*args) Also known as: has_att
Given a list of attribute names, returns the first attribute name for which there is a value.
37 38 39 40 41 42 |
# File 'lib/ruote/exp/ro_attributes.rb', line 37 def has_attribute(*args) args.each { |a| a = a.to_s; return a if attributes[a] != nil } nil end |
- (Object) initial_persist
Persists and fetches the _rev identifier from the storage.
Only used by the worker when creating the expression.
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/ruote/exp/ro_persist.rb', line 41 def initial_persist r = @context.storage.put(@h, :update_rev => true) raise( "initial_persist failed for " + #"#{Ruote.to_storage_id(h.fei)} #{tree.first} // #{r.inspect}" "#{Ruote.to_storage_id(h.fei)} #{tree[0]} #{tree[1].inspect}" ) if r != nil nil end |
- (Object) iterative_var_lookup(k)
TODO : redoc rewrite needed
This method is mostly used by the worker when looking up a process name or participant name bound under a variable.
115 116 117 118 119 120 121 122 |
# File 'lib/ruote/exp/ro_variables.rb', line 115 def iterative_var_lookup(k) v = lookup_variable(k) return [ k, v ] unless (v.is_a?(String) or v.is_a?(Symbol)) iterative_var_lookup(v) end |
- (Object) launch_sub(pos, subtree, opts = {})
– misc ++
450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 |
# File 'lib/ruote/exp/flowexpression.rb', line 450 def launch_sub(pos, subtree, opts={}) i = h.fei.merge( 'subid' => Ruote.generate_subid(subtree), 'expid' => pos) #p '=== launch_sub ===' #p [ :launcher, h.fei['expid'], h.fei['subid'], h.fei['wfid'] ] #p [ :launched, i['expid'], i['subid'], i['wfid'] ] forget = opts[:forget] register_child(i) unless forget variables = ( forget ? compile_variables : {} ).merge!(opts[:variables] || {}) @context.storage.put_msg( 'launch', 'fei' => i, 'parent_id' => forget ? nil : h.fei, 'tree' => subtree, 'workitem' => opts[:workitem] || h.applied_workitem, 'variables' => variables, 'forgotten' => forget) end |
- (Object) lookup_on_error
Looks up “on_error” attribute
491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 |
# File 'lib/ruote/exp/flowexpression.rb', line 491 def lookup_on_error if h.on_error self elsif h.parent_id par = parent # :( get_parent would probably be a better name for #parent #if par.nil? && ($DEBUG || ARGV.include?('-d')) # puts "~~" # puts "parent gone for" # puts "fei #{Ruote.sid(h.fei)}" # puts "tree #{tree.inspect}" # puts "replying to #{Ruote.sid(h.parent_id)}" # puts "~~" #end # is sometimes helpful during debug sessions par ? par.lookup_on_error : nil else nil end end |
- (Object) lookup_val(att_options = {})
104 105 106 107 108 109 110 111 |
# File 'lib/ruote/exp/ro_attributes.rb', line 104 def lookup_val(={}) lval( VV, s_cartesian(%w[ v var variable ], VV), s_cartesian(%w[ f fld field ], VV), ) end |
- (Object) lookup_val_prefix(prefix, att_options = {})
prefix = 'on' => will lookup on, on_val, on_value, on_v, on_var, on_variable, on_f, on_fld, on_field…
95 96 97 98 99 100 101 102 |
# File 'lib/ruote/exp/ro_attributes.rb', line 95 def lookup_val_prefix(prefix, ={}) lval( [ prefix ] + [ 'val', 'value' ].map { |s| "#{prefix}_#{s}" }, %w[ v var variable ].map { |s| "#{prefix}_#{s}" }, %w[ f fld field ].map { |s| "#{prefix}_#{s}" }, ) end |
- (Object) lookup_variable(var, prefix = nil) Also known as: v, lv
Looks up the value of a variable in expression tree (seen from a leaf, it looks more like a stack than a tree)
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/ruote/exp/ro_variables.rb', line 55 def lookup_variable(var, prefix=nil) var, prefix = split_prefix(var, prefix) return @context.storage.get_engine_variable(var) \ if prefix.length >= 2 return parent.lookup_variable(var, prefix) \ if h.parent_id && prefix.length >= 1 if h.variables val = Ruote.lookup(h.variables, var) return val if val != nil end if h.parent_id && h.parent_id['engine_id'] == @context.engine_id # # do not lookup variables in a remote engine ... (return parent.lookup_variable(var, prefix)) rescue nil # if the lookup fails (parent gone) then rescue and let go end @context.storage.get_engine_variable(var) end |
- (Object) name
585 586 587 |
# File 'lib/ruote/exp/flowexpression.rb', line 585 def name tree[0] end |
- (Object) parent
117 118 119 |
# File 'lib/ruote/exp/flowexpression.rb', line 117 def parent Ruote::Exp::FlowExpression.fetch(@context, h.parent_id) end |
- (Object) parent_id
113 114 115 |
# File 'lib/ruote/exp/flowexpression.rb', line 113 def parent_id h.parent_id ? Ruote::FlowExpressionId.new(h.parent_id) : nil end |
- (Object) persist_or_raise Also known as: persist
– duplication ahead ++
89 90 91 92 93 94 95 96 97 |
# File 'lib/ruote/exp/ro_persist.rb', line 89 def persist_or_raise r = try_persist raise( "persist failed for " + "#{Ruote.to_storage_id(h.fei)} #{tree.first} #{r.class}" ) if r end |
- (Object) reply(workitem)
A default implementation for all the expressions.
331 332 333 334 |
# File 'lib/ruote/exp/flowexpression.rb', line 331 def reply(workitem) reply_to_parent(workitem) end |
- (Object) reply_to_parent(workitem, delete = true)
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 |
# File 'lib/ruote/exp/flowexpression.rb', line 231 def reply_to_parent(workitem, delete=true) if h.tagname unset_variable(h.tagname) Ruote::Workitem.remove_tag(workitem, h.tagname) @context.storage.put_msg( 'left_tag', 'tag' => h.tagname, 'fei' => h.fei, 'workitem' => workitem) end if h.timeout_schedule_id && h.state != 'timing_out' @context.storage.delete_schedule(h.timeout_schedule_id) end if h.state == 'failing' # on_error is implicit (#fail got called) trigger('on_error', workitem) elsif h.state == 'cancelling' and h.on_cancel trigger('on_cancel', workitem) elsif h.state == 'cancelling' and h.on_re_apply trigger('on_re_apply', workitem) elsif h.state == 'timing_out' and h.on_timeout trigger('on_timeout', workitem) elsif h.lost and h.state == nil # do not reply, sit here (and wait for cancellation probably) else # vanilla reply (do_unpersist || return) if delete # remove expression from storage if h.parent_id @context.storage.put_msg( 'reply', 'fei' => h.parent_id, 'workitem' => workitem.merge!('fei' => h.fei), 'updated_tree' => h.updated_tree) # nil most of the time else @context.storage.put_msg( h.forgotten ? 'ceased' : 'terminated', 'wfid' => h.fei['wfid'], 'fei' => h.fei, 'workitem' => workitem) end end end |
- (Object) set_variable(var, val)
Sets a variable to a given value. (will set at the appropriate level).
94 95 96 97 98 99 |
# File 'lib/ruote/exp/ro_variables.rb', line 94 def set_variable(var, val) fexp, v = locate_var(var) fexp.un_set_variable(:set, v, val, (fexp.h.fei != h.fei)) if fexp end |
- (Object) to_h
Turns this FlowExpression instance into a Hash (well, just hands back the base hash behind it).
124 125 126 127 |
# File 'lib/ruote/exp/flowexpression.rb', line 124 def to_h @h end |
- (Object) tree
Returns the current version of the tree (returns the updated version if it got updated.
561 562 563 |
# File 'lib/ruote/exp/flowexpression.rb', line 561 def tree h.updated_tree || h.original_tree end |
- (Object) tree_children
593 594 595 |
# File 'lib/ruote/exp/flowexpression.rb', line 593 def tree_children tree[2] end |
- (Object) try_persist
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/ruote/exp/ro_persist.rb', line 54 def try_persist r = @context.storage.put(@h) #t = Thread.current.object_id.to_s[-3..-1] #puts "+ per #{h.fei['expid']} #{tree.first} #{h._rev} #{t} -> #{r.class}" #Ruote.p_caller('+ per') #if r != nil || h.fei['expid'] == '0_0' r end |
- (Object) try_unpersist
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/ruote/exp/ro_persist.rb', line 65 def try_unpersist r = @context.storage.delete(@h) #t = Thread.current.object_id.to_s[-3..-1] #puts "- unp #{h.fei['expid']} #{tree.first} #{h._rev} #{t} -> #{r.class}" #Ruote.p_caller('- unp') #if r != nil || h.fei['expid'] == '0_0' return r if r #if h.has_error err = @context.storage.get('errors', "err_#{Ruote.to_storage_id(h.fei)}") @context.storage.delete(err) if err #end # removes any error in the journal for this expression # since it will now be gone, no need to keep track of its errors nil end |
- (Object) unpersist_or_raise Also known as: unpersist
99 100 101 102 103 104 105 106 107 |
# File 'lib/ruote/exp/ro_persist.rb', line 99 def unpersist_or_raise r = try_unpersist raise( "unpersist failed for " + "#{Ruote.to_storage_id(h.fei)} #{tree.first} #{r.class}" ) if r end |
- (Object) unset_variable(var)
Unbinds a variables.
103 104 105 106 107 108 |
# File 'lib/ruote/exp/ro_variables.rb', line 103 def unset_variable(var) fexp, v = locate_var(var) fexp.un_set_variable(:unset, v, nil, (fexp.h.fei != h.fei)) if fexp end |
- (Object) update_tree(t = nil)
Updates the tree of this expression
update_tree(t)
will set the updated tree to t
update_tree
will copy (deep copy) the original tree as the updated_tree.
Adding a child to a sequence expression :
seq.update_tree
seq.updated_tree[2] << [ 'participant', { 'ref' => 'bob' }, [] ]
seq.do_persist
581 582 583 |
# File 'lib/ruote/exp/flowexpression.rb', line 581 def update_tree(t=nil) h.updated_tree = t || Ruote.fulldup(h.original_tree) end |
- (Object) variables
A shortcut to the variables held in the expression (nil if none held).
35 36 37 38 |
# File 'lib/ruote/exp/ro_variables.rb', line 35 def variables @h['variables'] end |