On Jun 3, 6:00 am, John Mettraux <[email protected]> wrote:
> 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 onhttp://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

Hi John,

Thanks for the quick response! I hadn't thought about setting up a
separate class and registering that as a participant in order to
accomplish the state change; I'll try that approach.

Regarding the contents of Server.all being set at process definition
time and not changing later despite changes in the database, would
this also be a viable alternative?

---------------
# Model
def self.pdef_create_email
  servers = Server.all
  Ruote.process_definition :name => 'create_email' do
    cursor do
      concurrence do
        servers.each do |server|
          remote_server :command => '/account/disable', :queue =>
"ruote_uuid-#{server.uuid}"
        end
      end
    end
  end

# Controller
@email = Email.create(:address => '[email protected]')
@email.wfid = RuoteKit.engine.launch(Email.pdef_create_email,
                                     :address => @email.address,
                                     :object_type => :email,
                                     :object_id => @email.id)
---------------

Please note that I like your method of using concurrent_iterator and
passing in the UUIDs better than this method, and I understand why you
would want to avoid mixing Ruby code into the pdef. However, I'm still
curious about whether or not the above method would work.

Thanks for all the help!

-- 
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

Reply via email to