Skip to content

Instantly share code, notes, and snippets.

@jmettraux
Created November 20, 2008 00:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmettraux/26847 to your computer and use it in GitHub Desktop.
Save jmettraux/26847 to your computer and use it in GitHub Desktop.
a conversation with Thibaut
require 'rufus/scheduler'
require 'openwfe/service'
require 'openwfe/listeners/listener'
module OpenWFE
class Emailistener < Service
include WorkItemListener
include Rufus::Schedulable
def initialize (service_name, application_context)
super
linfo { "new() EmailListener started!" }
end
#
# Polls the imap/pop3 account for incoming workitems/launchitems
#
def trigger (params)
ldebug { 'trigger()' }
mails = fetch_mail(params)
#
# assuming the emails have been turned into a list of hashes
mails.each do |mail|
workitem = if fei = mail[:flow_expression_id]
#
# there is a fei, it's a workitem coming back
wi = InFlowWorkItem.new
wi.fei = FlowExpressionId.from_s(fei)
wi
else
#
# no fei (no process instance awaiting) it's probably a launchitem
procdef = mail[:process_definition_url] || mail[:process_definition]
LaunchItem.new(procdef)
end
workitem.attributes = mail
# using the whole 'mail' hash as the workitem/launchitem payload
#handle_item(workitem)
get_engine.reply(workitem) # inlining... a bit more explicit
# resumes process instance or launches new one
linfo { "trigger() handled #{workitem.class}" }
end
end
protected
def fetch_mail (params)
# ...
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment