Class: Ruote::RevParticipant
- Inherits:
-
Object
- Object
- Ruote::RevParticipant
- Includes:
- LocalParticipant
- Defined in:
- lib/ruote/part/rev_participant.rb
Overview
This participant was born out of a suggestion from Jan Topiński in groups.google.com/group/openwferu-users/browse_thread/thread/be20a5d861556fd8
This participant is a gateway to code placed in a directory.
engine.register do
toto, Ruote::RevParticipant, :dir => 'participants/toto/'
end
Then in the participants/toto/ dir :
/my_workflow__0.1__toto_0.6.rb
# participant toto, workflow 'my_workflow' with revision '0.1'
/my_workflow__toto.rb
# participant toto, workflow 'my_workflow' any revision
/toto_0.6.rb
# participant toto with rev '0.6', any workflow
/toto.rb
# participant toto, any rev, any workflow
# ...
The scheme goes like :
/wf-name__wf-revision__participant-name__p-revision.rb
The files themselves look like :
def consume(workitem)
workitem.fields['kilroy'] = 'was here'
reply_to_engine(workitem)
end
The file directly contains the classical participant methods defined at the top level. #cancel, #accept?, #on_reply and of course #consume are OK.
Maybe, look at the tests for more clues :
https://github.com/jmettraux/ruote/blob/master/test/functional/ft_57_rev_participant.rb
Note : It’s probably not the best participant in a distributed context, it grabs the code to execute from a directory. If you use it in a distributed context, you’ll have to make sure to synchronize the directory to each host running a worker.
Warning : this participant trusts the code it deals with, there is no security check.
Instance Attribute Summary
Attributes included from LocalParticipant
#context, #fei, #flavour, #workitem
Instance Method Summary collapse
-
#initialize(opts = nil) ⇒ RevParticipant
constructor
TODO : how to deal with >= and ~> ?.
- #on_cancel ⇒ Object
-
#on_reply ⇒ Object
– def accept?(workitem) part = lookup_code part.respond_to?(:accept?) ? part.accept?(workitem) : true end.
- #on_workitem ⇒ Object
- #rtimeout(workitem) ⇒ Object
Methods included from LocalParticipant
#_accept?, #_dont_thread?, #_on_cancel, #_on_reply, #_on_workitem, #_rtimeout, #applied_workitem, #fexp, #is_cancelled?, #is_gone?, #lookup_variable, #participant_name, #re_dispatch, #reply_to_engine, #unschedule_re_dispatch
Methods included from ReceiverMixin
#fetch_flow_expression, #fetch_workitem, #flunk, #launch, #receive, #reply, #sign
Constructor Details
#initialize(opts = nil) ⇒ RevParticipant
TODO : how to deal with >= and ~> ?
88 89 90 91 92 93 94 95 |
# File 'lib/ruote/part/rev_participant.rb', line 88 def initialize(opts=nil) @dir = opts['dir'] raise ArgumentError.new( "missing option :dir for #{self.class}" ) unless @dir end |
Instance Method Details
#on_cancel ⇒ Object
105 106 107 108 109 110 111 |
# File 'lib/ruote/part/rev_participant.rb', line 105 def on_cancel Ruote.participant_send( lookup_code, [ :on_cancel, :cancel ], 'fei' => fei, 'flavour' => flavour) end |
#on_reply ⇒ Object
– def accept?(workitem)
part = lookup_code
part.respond_to?(:accept?) ? part.accept?(workitem) : true
end
Can’t do this at this level, since it isn’t the rev_participant’s own accept?, it has to go in lookup_code ++
123 124 125 126 127 128 129 130 |
# File 'lib/ruote/part/rev_participant.rb', line 123 def on_reply part = lookup_code if part.respond_to?(:on_reply) Ruote.participant_send(part, :on_reply, 'workitem' => workitem) end end |
#on_workitem ⇒ Object
97 98 99 100 101 102 103 |
# File 'lib/ruote/part/rev_participant.rb', line 97 def on_workitem Ruote.participant_send( lookup_code, [ :on_workitem, :consume ], 'workitem' => workitem) end |
#rtimeout(workitem) ⇒ Object
132 133 134 135 136 137 |
# File 'lib/ruote/part/rev_participant.rb', line 132 def rtimeout(workitem) part = lookup_code part.respond_to?(:rtimeout) ? part.rtimeout(workitem) : nil end |