On Mon, Jul 13, 2009 at 8:06 PM, 孫 皓<[email protected]> wrote:
>
> another problem is:  i want to make the qusetion and answer
> process to be atomic. reserve expression is good for this problem,
> but i can not make the expression work for me.. finding reason.
> ========================================================
>   concurrence do
>
>   # Question and Answer
>     listen :to => "check_result", :where => "${f:question}" do
>         participant :inform_owner, "activity" => "Please answer"
>         participant :require_answer, "activity" => "This is the answer"
>     end
>
>   # Job distribution.
>     sequence do
>       participant :ask_details, 'activity' => "Tell me the job details"
>       cursor do
>         participant :send_job, 'activity' => "Please do this work"
>         set :f => "rework", :val => false
>         participant :check_result,  'activity' => "evaluate the work"
>         rewind :if => "${f:rework} || ${f:question}"
>       end
>     end
>   end
> ========================================================
>
> picture is attached for more detail expression.

Hi 孫 皓,

many thanks for the picture :)

I'm wondering : why is a listen expression necessary ?

Why don't you write a simple process definition like :

---8<---
cursor do
  participant "interviewed_person", :timeout => '2d'
  rewind :if => '${f:__timed_out__}
  participant "interviewer"
end
--->8---

I guess there is some confusion between the "listen" expression and
the "listener" concept.

---8<---
engine.register_participant "interviewed_person", SunHaoMailParticipant

class SunHaoMailParticipant
  def consume (workitem)
    text = "Subject: question\n\n"
    text << workitem.fei.to_s << "\n"
    text << "\n"
    text << "please answer the following question :\n"
    #...
    Net::SMTP.start($server, $port) do |smtp|
      smtp.send_message(text, workitem.fields['from_address'],
workitem.field['to_address'])
    end
  end
end
--->8---

Then you could register a listener :

---8<---
engine.register_listener SunHaoMailListener, :frequency => '5m'

class SunHaoMailListener < Service
  include WorkItemListener

  def trigger (params)
    imap = Net::IMAP.new($server)
    imap.authenticate('LOGIN', $imap_user, $imap_password)
    imap.examine('INBOX')
    imap.search([ 'RECENT' ]).each do |message_id|
      lines = imap.fetch(message_id, "BODY").split("\n")
      fei = lines.shift
      answer = lines.join("\n")
      reply_to_engine(fei, answer)
    end
    # TODO : delete all those read messages
  end

  def reply_to_engine (fei, answer)
    fei = OpenWFE::FlowExpressionId.from_s(fei)
    fexp = get_engine.get_expression_storage[fei]
    workitem = fexp.applied_workitem
    workitem.fields['answer'] = answer
    get_engine.reply(workitem)
  rescue Exception => e
    # ignore...
  end
end
--->8---

Thus you would have a pair SMTP participant + IMAP listener and very
simple process definitons. And atomicity is guaranteed (well in my
opinion at least).


What do you think ?

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

Reply via email to