Hello Reed,
I don't think you need to implement the whole participant by yourself.
This should be sufficient:
---8<---
class ReedParticipant < Ruote::StorageParticipant
def on_workitem
super
PrivatePub.publish_to(
'/messages/new', :workitem_message => 'New task available.')
end
end
--->8---
It's the regular storage participant, it receives the workitem, stores in the
storage and then notifies the user thanks to PrivatePub.
In config/initializers/ruote-kit.rb you have to bind the participant names to
that participant:
---8<---
RuoteKit.engine.register do
participant 'user_.*', ReedParticipant
# all participant whose name start with 'user_' are notified
catchall Ruote::StorageParticipant
# no notifications for the rest
end
--->8---
> Let me try to guess how a custom participant would work:
OK, let's walk through those methods together.
> The #on_workitem method would call PrivatePub#publish_to with the
> user's session id and new task.
Yes, but in the ReedParticipant above we also store the workitem (thanks to
the Ruote::StorageParticipant parent class).
> #on_cancel would cancel the workitem, perhaps after a certain amount
> of time had passed.
#on_cancel is called when the flow the participant is in gets cancelled.
There are roughly three types of cancellation: deliberate cancellation (of
a workflow or of a part of it), timeout cancellation and rollback
cancellation (trigerred by an error handler).
> #on_reply would define what to do with the processed workitem before
> continuing.
Yes, it gives you an opportunity to tweak the workitem right before the
participant hands it back to the engine.
> Then I would need to implement a receiver that would be called by the
> controller when the user submits the processed workitem. How would
> this receiver respond to the correct workitem? I assume that would be
> defined by #workitem_from_msg in the example
> http://ruote.rubyforge.org/implementing_participants.html#on_reply
Yes, exactly. But as we've seen above, you don't seem to need a receiver at
all, you are merely adding a bell to the Ruote::StorageParticipant.
I hope it all makes sense, best regards,
--
John Mettraux - http://lambda.io/processi