Class: Nifty::Event::Processor

Inherits:
Object
  • Object
show all
Defined in:
lib/nifty/event/processor.rb

Overview

Processing of events

Author:

  • Michal Kimle

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(backend, transfer_method, parameters) ⇒ Processor

Constructor

Parameters:



17
18
19
20
21
22
# File 'lib/nifty/event/processor.rb', line 17

def initialize(backend, transfer_method, parameters)
  @backend = backend
  @transfer_method = transfer_method
  @parameters = parameters
  @error_code = Nifty::ExitCodes::NO_ERROR_EXIT_CODE
end

Instance Attribute Details

#backendNifty::Backend (readonly)

Returns the current value of backend.

Returns:



9
10
11
# File 'lib/nifty/event/processor.rb', line 9

def backend
  @backend
end

#error_codeObject (readonly)

Returns the value of attribute error_code.



10
11
12
# File 'lib/nifty/event/processor.rb', line 10

def error_code
  @error_code
end

#parametersHash (readonly)

Returns the current value of parameters.

Returns:

  • (Hash)

    the current value of parameters



9
10
11
# File 'lib/nifty/event/processor.rb', line 9

def parameters
  @parameters
end

#transfer_methodNifty::TransferMethod (readonly)

Returns the current value of transfer_method.

Returns:



9
10
11
# File 'lib/nifty/event/processor.rb', line 9

def transfer_method
  @transfer_method
end

Instance Method Details

#process_eventsObject

Runs the whole event processing



26
27
28
29
30
31
32
# File 'lib/nifty/event/processor.rb', line 26

def process_events
  run_backend_pre
  run_events
  run_backend_post

  error_code
end

#run_backend_postObject

Runs backend’s postprocessing routine



43
44
45
46
# File 'lib/nifty/event/processor.rb', line 43

def run_backend_post
  logger.debug('Running backend post-processing...')
  backend.post(parameters) if backend.respond_to? 'post'
end

#run_backend_preObject

Runs backend’s preprocessing routine



36
37
38
39
# File 'lib/nifty/event/processor.rb', line 36

def run_backend_pre
  logger.debug('Running backend pre-processing...')
  backend.pre(parameters) if backend.respond_to? 'pre'
end

#run_eventsObject

Takes care of event processing. All the events are loaded, converted and run.



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/nifty/event/processor.rb', line 50

def run_events
  events = prepare_events
  logger.debug("Events ready to run: #{events}")
  events.each do |event, file|
    begin
      event.run

      # clean event's descriptor so it won't be processed again
      FileUtils.rm file
    rescue Nifty::Errors::Events::EventError => ex
      logger.error "Unable to process event #{event.inspect} from descriptor #{file.inspect}: #{ex.message}."
      @error_code = Nifty::ExitCodes::EVENT_PROCESSING_ERROR_EXIT_CODE
      break
    rescue SystemCallError => ex
      logger.error "Cannot delete descriptor file #{file.inspect} of already processed event: #{ex.message}."
      @error_code = Nifty::ExitCodes::EVENT_CLEANUP_ERROR_EXIT_CODE
      break
    end
  end
end