Class OpenWFE::FileListener
In: lib/openwfe/listeners/listeners.rb
Parent: Service

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.

Methods

load_object   new   trigger  

Included Modules

WorkItemListener Rufus::Schedulable

Attributes

workdir  [R] 

Public Class methods

[Source]

    # File lib/openwfe/listeners/listeners.rb, line 75
75:         def initialize (service_name, application_context)
76: 
77:             super
78: 
79:             @workdir = get_work_directory + "/in/"
80: 
81:             linfo { "new() workdir is '#{@workdir}'" }
82:         end

Public Instance methods

Will ‘find’ files in the work directory (by default ./work/in/), extract the workitem in them and feed it back to the engine.

[Source]

     # File lib/openwfe/listeners/listeners.rb, line 88
 88:         def trigger (params)
 89:             # no synchronization for now
 90: 
 91:             ldebug { "trigger()" }
 92: 
 93:             FileUtils.makedirs(@workdir) unless File.exist?(@workdir)
 94: 
 95:             Find.find(@workdir) do |path|
 96: 
 97:                 next if File.stat(path).directory?
 98: 
 99:                 ldebug { "trigger() considering file '#{path}'" }
100: 
101:                 begin
102: 
103:                     object = load_object(path)
104: 
105:                     handle_item(object) if object
106: 
107:                 rescue Exception => e
108: 
109:                     linfo do
110:                         "trigger() failure while loading from '#{path}'. " +
111:                         "Resuming... \n" +
112:                         OpenWFE::exception_to_s(e)
113:                     end
114:                 end
115:             end
116:         end

Protected Instance methods

Turns a file into a Ruby instance. This base implementation does it via YAML.

[Source]

     # File lib/openwfe/listeners/listeners.rb, line 124
124:             def load_object (path)
125: 
126:                 return nil unless path.match ".*\.yaml$"
127: 
128:                 object = YAML.load_file(path)
129: 
130:                 File.delete(path)
131: 
132:                 return object
133:             end

[Validate]