Class: OpenWFE::YamlErrorJournal

Inherits:
ErrorJournal show all
Defined in:
lib/openwfe/expool/errorjournal.rb

Overview

A Journal that only keep track of error in process execution.

Instance Attribute Summary collapse

Attributes included from ServiceMixin

#service_name

Attributes included from Contextual

#application_context

Instance Method Summary collapse

Methods inherited from ErrorJournal

#has_errors?, reduce_error_list

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

#service_init, #stop

Methods included from Contextual

#get_work_directory, #init_service, #lookup

Methods included from Logging

#ldebug, #ldebug_callstack, #lerror, #lfatal, #linfo, #llog, #lunknown, #lwarn

Constructor Details

#initialize(service_name, application_context) ⇒ YamlErrorJournal

Returns a new instance of YamlErrorJournal.



329
330
331
332
333
334
335
336
337
338
339
340
341
# File 'lib/openwfe/expool/errorjournal.rb', line 329

def initialize (service_name, application_context)

    require 'openwfe/storage/yamlcustom'
        # making sure this file has been required at this point
        # this yamlcustom thing prevents the whole OpenWFE ecosystem
        # to get serialized :)

    super

    @workdir = get_work_directory + "/ejournal"

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

Instance Attribute Details

#workdirObject (readonly)

Returns the value of attribute workdir.



327
328
329
# File 'lib/openwfe/expool/errorjournal.rb', line 327

def workdir
  @workdir
end

Instance Method Details

#copy_error_log_to(wfid, path) ⇒ Object

Copies the error log of a process instance to a give path (and filename).

Could be useful when one has to perform replay operations and wants to keep a copy of the original error.



366
367
368
369
370
# File 'lib/openwfe/expool/errorjournal.rb', line 366

def copy_error_log_to (wfid, path)

    original_path = get_path wfid
    FileUtils.copy_file original_path, path
end

#get_error_log(wfid) ⇒ Object

Returns a list (older first) of the errors for a process instance identified by its fei or wfid.

Will return an empty list if there a no errors for the process instances.



350
351
352
353
354
355
356
357
# File 'lib/openwfe/expool/errorjournal.rb', line 350

def get_error_log (wfid)

    path = get_path wfid

    return [] unless File.exist?(path)

    read_error_log_from path
end

#get_error_logsObject

Reads all the error logs currently stored. Returns a hash wfid –> error list.



438
439
440
441
442
443
444
445
446
447
448
449
450
# File 'lib/openwfe/expool/errorjournal.rb', line 438

def get_error_logs

    result = {}

    Find.find(@workdir) do |path|
        next unless path.endswith(".ejournal")
        wfid = path[0..-9]
        log = read_error_log wfid
        result[wfid] = log
    end

    result
end

#read_error_log_from(path) ⇒ Object

Reads an error log from a specific file (possibly as copied over via copy_error_log_to()).



376
377
378
379
380
381
382
383
384
# File 'lib/openwfe/expool/errorjournal.rb', line 376

def read_error_log_from (path)

    raise "no error log file at #{path}" unless File.exist?(path)

    File.open(path) do |f|
        s = YAML.load_stream f
        s.documents
    end
end

#remove_error_log(wfid) ⇒ Object

Removes the error log of a specific process instance. Could be a good idea after a succesful replay operation.

‘wfid’ may be either a workflow instance id (String) either a FlowExpressionId instance.



393
394
395
396
397
398
# File 'lib/openwfe/expool/errorjournal.rb', line 393

def remove_error_log (wfid)

    path = get_path wfid

    File.delete(path) if File.exist?(path)
end

#remove_errors(wfid, errors) ⇒ Object

Removes a list of errors from this error journal.



403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
# File 'lib/openwfe/expool/errorjournal.rb', line 403

def remove_errors (wfid, errors)

    errors = Array(errors)

    # load all errors

    log = get_error_log wfid

    # remove the given errors

    errors.each do |e|
        log.delete e
    end

    # rewrite error file

    path = get_path wfid

    if log.size > 0

        File.open(path, "w") do |f|
            log.each do |e|
                f.puts e.to_yaml
            end
        end
    else

        File.delete path
    end
end