Class: OpenWFE::FileParticipant

Inherits:
Object
  • Object
show all
Includes:
LocalParticipant
Defined in:
lib/openwfe/participants/participants.rb

Overview

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…

Instance Attribute Summary collapse

Attributes included from Contextual

#application_context

Instance Method Summary collapse

Methods included from LocalParticipant

#call_block, #get_flow_expression, #reply_to_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

Constructor Details

#initialize(context_or_dir = nil) ⇒ FileParticipant

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



68
69
70
71
72
73
# File 'lib/openwfe/participants/participants.rb', line 68

def initialize (context_or_dir=nil)

    @workdir = get_work_directory(context_or_dir) + "/out/"

    @reply_anyway = false
end

Instance Attribute Details

#reply_anywayObject

Returns the value of attribute reply_anyway.



62
63
64
# File 'lib/openwfe/participants/participants.rb', line 62

def reply_anyway
  @reply_anyway
end

#workdirObject

Returns the value of attribute workdir.



62
63
64
# File 'lib/openwfe/participants/participants.rb', line 62

def workdir
  @workdir
end

Instance Method Details

#consume(workitem) ⇒ Object

The method called by the engine for each incoming workitem.



78
79
80
81
82
83
84
85
86
87
# File 'lib/openwfe/participants/participants.rb', line 78

def consume (workitem)

    FileUtils.makedirs(@workdir) unless File.exist?(@workdir)

    file_name = @workdir + determine_file_name(workitem)

    dump_to_file(file_name, workitem)

    reply_to_engine(workitem) if @reply_anyway
end

#determine_file_name(workitem) ⇒ Object

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.



107
108
109
110
111
112
113
114
115
116
# File 'lib/openwfe/participants/participants.rb', line 107

def determine_file_name (workitem)

    fei = workitem.fei

    OpenWFE::ensure_for_filename(
        "#{fei.wfid}_#{fei.expression_id}__" +
        "#{fei.workflow_definition_name}__" +
        "#{fei.workflow_definition_revision}" +
        "#{workitem.participant_name}.yaml")
end

#dump_to_file(file_name, workitem) ⇒ Object

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



94
95
96
97
98
99
# File 'lib/openwfe/participants/participants.rb', line 94

def dump_to_file (file_name, workitem)

    File.open(file_name, "w") do |file|
        file.print encode_workitem(workitem)
    end
end