Class OpenWFE::FileParticipant

  1. lib/openwfe/participants/participants.rb
Parent: Object

Just dumps the incoming workitem in a file as a YAML String.

By default, this participant will not reply to the engine once the workitem got dumped to its file, but you can set its reply_anyway field to true to make it reply anyway...

Methods

public class

  1. new

public instance

  1. consume
  2. determine_file_name
  3. dump_to_file

protected instance

  1. encode_workitem

Included modules

  1. LocalParticipant

Attributes

reply_anyway [RW]
workdir [RW]

Public class methods

new (context_or_dir=nil)

The constructor expects as a unique optional param either the application_context either the ‘output’ dir for the participant.

[show source]
    # File lib/openwfe/participants/participants.rb, line 54
54:     def initialize (context_or_dir=nil)
55: 
56:       @workdir = get_work_directory(context_or_dir) + '/out/'
57: 
58:       @reply_anyway = false
59:     end

Public instance methods

consume (workitem)

The method called by the engine for each incoming workitem.

[show source]
    # File lib/openwfe/participants/participants.rb, line 64
64:     def consume (workitem)
65: 
66:       FileUtils.mkdir_p(@workdir) unless File.exist?(@workdir)
67: 
68:       file_name = @workdir + determine_file_name(workitem)
69: 
70:       dump_to_file(file_name, workitem)
71: 
72:       reply_to_engine(workitem) if @reply_anyway
73:     end
determine_file_name (workitem)

You can override this method to control into which file (name) each workitem gets dumped. You could even have a unique file for all workitems transiting through this participant.

[show source]
     # File lib/openwfe/participants/participants.rb, line 93
 93:     def determine_file_name (workitem)
 94: 
 95:       fei = workitem.fei
 96: 
 97:       OpenWFE::ensure_for_filename(
 98:         "#{fei.wfid}_#{fei.expression_id}__" +
 99:         "#{fei.workflow_definition_name}__" +
100:         "#{fei.workflow_definition_revision}__" +
101:         "#{workitem.participant_name}.yaml")
102:     end
dump_to_file (file_name, workitem)

This method does the actual job of dumping the workitem (as some YAML to a file). It can be easily overriden.

[show source]
    # File lib/openwfe/participants/participants.rb, line 80
80:     def dump_to_file (file_name, workitem)
81: 
82:       File.open(file_name, 'w') do |file|
83:         file.print(encode_workitem(workitem))
84:       end
85:     end

Protected instance methods

encode_workitem (wi)

By default, uses YAML to serialize the workitem (of course you can override this method).

[show source]
     # File lib/openwfe/participants/participants.rb, line 110
110:     def encode_workitem (wi)
111:       YAML.dump(wi)
112:     end