On Thu, Jun 03, 2010 at 05:09:20AM -0700, threetee wrote:
>
> I'm using ruote and ruote-amqp from within a Rails app via ruote-kit
> (basing my app on http://github.com/threetee/ruote-rails-example). I'd
> like to be able to execute Ruby code from within my process definition
> so that I can call methods on my Rails models. It doesn't seem to be a
> problem to include Ruby code in the process definition, but I'm having
> trouble figuring out how to reference workitem fields from the pdef.
Hello,
be careful : those, Ruote.process_definition { ... } calls generate the process
definition immediately. That means the the Ruby code you place in them is not
executed at "process run time", but at "process definition time".
> Example:
> ----------------------
> # In the model:
> servers = Server.all
>
> PDEF = Ruote.process_definition :name => 'create_email' do
> cursor do
> approver :task => 'approve_email'
> cancel_process :if => '${account_denied}'
>
> # Set the state to 'provisioning' - this doesn't work
> # Email.find(eval('${object_id}')).begin_provisioning
>
> # Provision the account on the ingress servers
> concurrence do
> servers.each do |server|
> remote_server :command => '/account/disable', :queue =>
> "ruote_uuid-#{server.uuid}"
> end
> end
> end
> end
>
> # Launch the process
> @email = Email.create(:address => '[email protected]')
> RuoteKit.engine.launch(PDEF, :address => @email.address, :object_type
> => :email, :object_id => @email.id)
> ---------------------
What about something like :
---8<---
PDEF = Ruote.process_definition :name => 'create_email' do
cursor do
approver :task => 'approve_email'
cancel_process :if => '${f:account_denied}'
provisioner
# Provision the account on the ingress servers
concurrent-iterator :on_field => 'server_uuids', :to_field => 'server_uuid'
do
remote_server :command => '/account/disable', :queue =>
'ruote_uuid-${f:server_uuid}'
end
end
end
class Provisioner
include Ruote::LocalParticipant
def initialize (options)
end
def consume (workitem)
Email.find(workitem.fields['object_id']).begin_provisioning
reply_to_engine(workitem)
end
end
RuoteKit.engine.register_participant 'provisioner', Provisioner
# Launch the process
@email = Email.create(:address => '[email protected]')
RuoteKit.engine.launch(
PDEF,
'server_uuids' => Server.all.collect { |s| s.uuid },
:address => @email.address,
:object_type => :email,
:object_id => @email.id)
--->8---
> In the above example, iterating over the servers AR results works
> properly, but I can't figure out how to reference the object_id field
> from the workitem (see the commented Email.find). Anybody have any
> tips on how to do this properly?
Does it really work properly ? You're placing the result of
Ruote.process_definition into the PDEF constant. A constant can get reassigned.
It means that you're stuck with the result of Server.all you had a constant
definition time (process definition time).
My version works around those issues.
Best regards,
--
John Mettraux - http://jmettraux.wordpress.com
--
you received this message because you are subscribed to the "ruote users" group.
to post : send email to [email protected]
to unsubscribe : send email to [email protected]
more options : http://groups.google.com/group/openwferu-users?hl=en