Class: OpenWFE::FileListener
- Includes:
- WorkItemListener, Rufus::Schedulable
- Defined in:
- lib/openwfe/listeners/listeners.rb
Overview
Polls a directory for incoming workitems (as files).
Workitems can be instances of InFlowWorkItem or LaunchItem.
require 'openwfe/listeners/listeners'
engine.add_workitem_listener(OpenWFE::FileListener, "500")
In this example, the directory ./work/in/ will be polled every 500 milliseconds for incoming workitems (or launchitems).
You can override the load_object(path) method to manage other formats then YAML.
Instance Attribute Summary collapse
-
#workdir ⇒ Object
readonly
Returns the value of attribute workdir.
Attributes included from Contextual
Attributes included from ServiceMixin
Instance Method Summary collapse
-
#initialize(service_name, application_context) ⇒ FileListener
constructor
A new instance of FileListener.
-
#trigger(params) ⇒ Object
Will ‘find’ files in the work directory (by default ./work/in/), extract the workitem in them and feed it back to the engine.
Methods included from Contextual
#get_work_directory, #init_service, #lookup
Methods included from Logging
#ldebug, #ldebug_callstack, #lerror, #lfatal, #linfo, #llog, #lunknown, #lwarn
Methods included from OwfeServiceLocator
#get_engine, #get_error_journal, #get_expool, #get_expression_map, #get_expression_pool, #get_expression_storage, #get_expression_storages, #get_journal, #get_participant_map, #get_scheduler, #get_wfid_generator
Methods included from ServiceMixin
Constructor Details
#initialize(service_name, application_context) ⇒ FileListener
Returns a new instance of FileListener.
75 76 77 78 79 80 81 82 |
# File 'lib/openwfe/listeners/listeners.rb', line 75 def initialize (service_name, application_context) super @workdir = get_work_directory + "/in/" linfo { "new() workdir is '#{@workdir}'" } end |
Instance Attribute Details
#workdir ⇒ Object (readonly)
Returns the value of attribute workdir.
73 74 75 |
# File 'lib/openwfe/listeners/listeners.rb', line 73 def workdir @workdir end |
Instance Method Details
#trigger(params) ⇒ Object
Will ‘find’ files in the work directory (by default ./work/in/), extract the workitem in them and feed it back to the engine.
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/openwfe/listeners/listeners.rb', line 88 def trigger (params) # no synchronization for now ldebug { "trigger()" } FileUtils.makedirs(@workdir) unless File.exist?(@workdir) Find.find(@workdir) do |path| next if File.stat(path).directory? ldebug { "trigger() considering file '#{path}'" } begin object = load_object(path) handle_item(object) if object rescue Exception => e linfo do "trigger() failure while loading from '#{path}'. " + "Resuming... \n" + OpenWFE::exception_to_s(e) end end end end |