Module: Ruote::ReceiverMixin
- Included in:
- Engine, LocalParticipant, Receiver
- Defined in:
- lib/ruote/receiver/base.rb
Overview
The core methods for the Receiver class (sometimes a Mixin is easier to integrate).
(The engine itself includes this mixin, the LocalParticipant module includes it as well).
Instance Method Summary collapse
-
#applied_workitem(fei) ⇒ Object
(also: #workitem)
A convenience methods for advanced users (like Oleg).
-
#fetch_flow_expression(workitem_or_fei) ⇒ Object
(also: #fexp)
Convenience method, given a workitem or a fei, returns the corresponding flow expession.
-
#launch(process_definition, fields = {}, variables = {}) ⇒ Object
Given a process definitions and optional initial fields and variables, launches a new process instance.
-
#receive(workitem) ⇒ Object
This method pipes back a workitem into the engine, letting it resume in its flow, hopefully.
-
#reply(workitem) ⇒ Object
Wraps a call to receive(workitem).
-
#reply_to_engine(workitem) ⇒ Object
Wraps a call to receive(workitem).
-
#sign ⇒ Object
A receiver signs a workitem when it comes back.
Instance Method Details
#applied_workitem(fei) ⇒ Object Also known as: workitem
A convenience methods for advanced users (like Oleg).
Given a fei (flow expression id), fetches the workitem as stored in the expression with that fei. This is the “applied workitem”, if the workitem is currently handed to a participant, this method will return the workitem as applied, not the workitem as saved by the participant/user in whatever worklist it uses. If you need that workitem, do the vanilla thing and ask it to the [storage] participant or its worklist.
The fei might be a string fei (result of fei.to_storage_id), a FlowExpressionId instance or a hash.
on_terminate processes are not triggered for on_error processes. on_error processes are triggered for on_terminate processes as well.
143 144 145 146 |
# File 'lib/ruote/receiver/base.rb', line 143 def applied_workitem(fei) Ruote::Workitem.new(fexp(fei).h.applied_workitem) end |
#fetch_flow_expression(workitem_or_fei) ⇒ Object Also known as: fexp
Convenience method, given a workitem or a fei, returns the corresponding flow expession.
112 113 114 115 116 117 |
# File 'lib/ruote/receiver/base.rb', line 112 def fetch_flow_expression(workitem_or_fei) Ruote::Exp::FlowExpression.fetch( @context, Ruote::FlowExpressionId.extract_h(workitem_or_fei)) end |
#launch(process_definition, fields = {}, variables = {}) ⇒ Object
Given a process definitions and optional initial fields and variables, launches a new process instance.
This method is mostly used from the Ruote::Engine class (which includes this mixin).
process_definition must be a result of Ruote.process_definition call or XML or JSON serialized process definition, as accepted by Ruote::Reader#read.
fields are workflow parameters that will be placed in workitem.fields.
variables contain engine variables.
66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/ruote/receiver/base.rb', line 66 def launch(process_definition, fields={}, variables={}) wfid = @context.wfidgen.generate @context.storage.put_msg( 'launch', 'wfid' => wfid, 'tree' => @context.reader.read(process_definition), 'workitem' => { 'fields' => fields }, 'variables' => variables) wfid end |
#receive(workitem) ⇒ Object
This method pipes back a workitem into the engine, letting it resume in its flow, hopefully.
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/ruote/receiver/base.rb', line 40 def receive(workitem) workitem = workitem.to_h if workitem.respond_to?(:to_h) @context.storage.put_msg( 'receive', 'fei' => workitem['fei'], 'workitem' => workitem, 'participant_name' => workitem['participant_name'], 'receiver' => sign) end |
#reply(workitem) ⇒ Object
Wraps a call to receive(workitem)
Not aliasing so that if someone changes the receive implementation, reply is affected as well.
85 86 87 88 |
# File 'lib/ruote/receiver/base.rb', line 85 def reply(workitem) receive(workitem) end |
#reply_to_engine(workitem) ⇒ Object
Wraps a call to receive(workitem)
Not aliasing so that if someone changes the receive implementation, reply_to_engine is affected as well.
95 96 97 98 |
# File 'lib/ruote/receiver/base.rb', line 95 def reply_to_engine(workitem) receive(workitem) end |
#sign ⇒ Object
A receiver signs a workitem when it comes back.
Not used much as of now.
104 105 106 107 |
# File 'lib/ruote/receiver/base.rb', line 104 def sign self.class.to_s end |