Class: Ruote::RevParticipant

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Methods included from LocalParticipant

#re_dispatch, #unschedule_re_dispatch

Methods included from ReceiverMixin

#applied_workitem, #fetch_flow_expression, #launch, #receive, #reply, #reply_to_engine, #sign

Constructor Details

#initialize(opts = nil) ⇒ RevParticipant

TODO : how to deal with >= and ~> ?

Raises:

  • (ArgumentError)


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

#cancel(fei, flavour) ⇒ Object



102
103
104
105
# File 'lib/ruote/part/rev_participant.rb', line 102

def cancel(fei, flavour)

  lookup_code(fei).cancel(fei, flavour)
end

#consume(workitem) ⇒ Object



97
98
99
100
# File 'lib/ruote/part/rev_participant.rb', line 97

def consume(workitem)

  lookup_code(workitem).consume(workitem)
end

#on_reply(workitem) ⇒ Object

– def accept?(workitem)

part = lookup_code(workitem)
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 ++



117
118
119
120
121
# File 'lib/ruote/part/rev_participant.rb', line 117

def on_reply(workitem)

  part = lookup_code(workitem)
  part.on_reply(workitem) if part.respond_to?(:on_reply)
end

#rtimeout(workitem) ⇒ Object



123
124
125
126
127
128
# File 'lib/ruote/part/rev_participant.rb', line 123

def rtimeout(workitem)

  part = lookup_code(workitem)

  part.respond_to?(:rtimeout) ? part.rtimeout(workitem) : nil
end