Class: Ddr::Batch::BatchProcessor

Inherits:
Object
  • Object
show all
Defined in:
app/scripts/ddr/batch/batch_processor.rb

Constant Summary collapse

LOG_CONFIG_FILEPATH =
File.join(Rails.root, 'config', 'log4r_batch_processor.yml')
DEFAULT_LOG_DIR =
File.join(Rails.root, 'log')
DEFAULT_LOG_FILE =
"batch_processor_log.txt"
PASS =
"PASS"
FAIL =
"FAIL"

Instance Method Summary collapse

Constructor Details

#initialize(batch, operator = nil, opts = {}) ⇒ BatchProcessor

Options

:log_dir - optional - directory for log file - default is given in DEFAULT_LOG_DIR
:log_file - optional - filename of log file - default is given in DEFAULT_LOG_FILE
:skip_validation - optional - whether to skip batch object validation step when processing - default is false
:ignore_validation_errors - optional - whether to continue processing even if batch object validation errors occur - default is false


15
16
17
18
19
20
21
22
# File 'app/scripts/ddr/batch/batch_processor.rb', line 15

def initialize(batch, operator=nil, opts={})
  @batch = batch
  @operator = operator
  @bp_log_dir = opts.fetch(:log_dir, DEFAULT_LOG_DIR)
  @bp_log_file = opts.fetch(:log_file, DEFAULT_LOG_FILE)
  @skip_validation = opts.fetch(:skip_validation, false)
  @ignore_validation_errors = opts.fetch(:ignore_validation_errors, false)
end

Instance Method Details

#executeObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/scripts/ddr/batch/batch_processor.rb', line 24

def execute
  config_logger
  if @batch
    initiate_batch_run
    unless @skip_validation
      valid_batch = validate_batch
      @batch.update_attributes(status: Batch::STATUS_INVALID) unless valid_batch
    end
    if @skip_validation || @ignore_validation_errors || valid_batch
      process_batch
    end
    close_batch_run
  end
  save_logfile
  send_notification if @batch.user && @batch.user.email
end