Class: Ruote::Exp::WaitExpression

Inherits:
FlowExpression show all
Defined in:
lib/ruote/exp/fe_wait.rb

Overview

Waits (sleeps) for a given period of time before resuming the flow.

sequence do
  accounting :task => 'invoice'
  wait '30d' # 30 days
  accounting :task => 'check if customer paid'
end

‘_sleep’ is also OK

_sleep '7d10h' # 7 days and 10 hours

(the underscore prevents collision with Ruby’s sleep method)

:for and :until

‘wait’ accepts as well :

wait :for => '30d' # wait for 30 days
wait :until => '2011/12/10 12:00:00' # any parseable date/time format

Constant Summary

Constants inherited from FlowExpression

FlowExpression::COMMON_ATT_KEYS

Instance Attribute Summary

Attributes inherited from FlowExpression

#context, #error, #h

Instance Method Summary collapse

Methods inherited from FlowExpression

#ancestor?, #att, #attribute, #attribute_text, #attributes, #compile_atts, #compile_variables, do_action, #do_apply, #do_cancel, #do_fail, #do_pause, #do_persist, #do_reply, #do_resume, #do_unpersist, #expand_atts, #fei, fetch, from_h, #handle_on_error, #has_attribute, #initial_persist, #initialize, #iterative_var_lookup, #launch_sub, #lookup_on_error, #lookup_val, #lookup_val_prefix, #lookup_variable, #name, names, #parent, #parent_id, #persist_or_raise, #reply, #reply_to_parent, #set_variable, #to_h, #tree, #tree_children, #try_persist, #try_unpersist, #unpersist_or_raise, #unset_variable, #update_tree, #variables

Methods included from WithMeta

#class_def, included

Methods included from WithH

included

Constructor Details

This class inherits a constructor from Ruote::Exp::FlowExpression

Instance Method Details

#applyObject



54
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
# File 'lib/ruote/exp/fe_wait.rb', line 54

def apply

  h.for = attribute(:for) || attribute_text
  h.until = attribute(:until)

  s = h.for
  s = h.until if s == ''

  h.at = s

  if h.at

    h.schedule_id = @context.storage.put_schedule(
      'at',
      h.fei,
      h.at,
      'action' => 'reply',
      'fei' => h.fei,
      'workitem' => h.applied_workitem)

    persist_or_raise

  else

    reply_to_parent(h.applied_workitem)
  end
end

#cancel(flavour) ⇒ Object

– no need to override, simply reply to parent expression. def reply (workitem) end ++



88
89
90
91
92
# File 'lib/ruote/exp/fe_wait.rb', line 88

def cancel(flavour)

  @context.storage.delete_schedule(h.schedule_id)
  reply_to_parent(h.applied_workitem)
end