Class: Nifty::Event::Processor
- Inherits:
-
Object
- Object
- Nifty::Event::Processor
- Defined in:
- lib/nifty/event/processor.rb
Overview
Processing of events
Instance Attribute Summary collapse
-
#backend ⇒ Nifty::Backend
readonly
The current value of backend.
-
#error_code ⇒ Object
readonly
Returns the value of attribute error_code.
-
#parameters ⇒ Hash
readonly
The current value of parameters.
-
#transfer_method ⇒ Nifty::TransferMethod
readonly
The current value of transfer_method.
Instance Method Summary collapse
-
#initialize(backend, transfer_method, parameters) ⇒ Processor
constructor
Constructor.
-
#process_events ⇒ Object
Runs the whole event processing.
-
#run_backend_post ⇒ Object
Runs backend’s postprocessing routine.
-
#run_backend_pre ⇒ Object
Runs backend’s preprocessing routine.
-
#run_events ⇒ Object
Takes care of event processing.
Constructor Details
#initialize(backend, transfer_method, parameters) ⇒ Processor
Constructor
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
#backend ⇒ Nifty::Backend (readonly)
Returns the current value of backend.
9 10 11 |
# File 'lib/nifty/event/processor.rb', line 9 def backend @backend end |
#error_code ⇒ Object (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 |
#parameters ⇒ Hash (readonly)
Returns the current value of parameters.
9 10 11 |
# File 'lib/nifty/event/processor.rb', line 9 def parameters @parameters end |
#transfer_method ⇒ Nifty::TransferMethod (readonly)
Returns the current value of transfer_method.
9 10 11 |
# File 'lib/nifty/event/processor.rb', line 9 def transfer_method @transfer_method end |
Instance Method Details
#process_events ⇒ Object
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_post ⇒ Object
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_pre ⇒ Object
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_events ⇒ Object
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 |