Module: EXEL::ProcessorHelper Deprecated
- Defined in:
- lib/exel/processor_helper.rb
Overview
Deprecated.
Most functionality replaced by Middleware::Logging middleware.
Helper methods useful to processors
Class Method Summary collapse
Instance Method Summary collapse
- #ensure_transaction_duration(duration, start_time) ⇒ Object
- #file_size_in_mb(file) ⇒ Object
- #log(message) ⇒ Object
- #log_error(message) ⇒ Object
- #log_exception(message = '') ⇒ Object
- #log_info(message) ⇒ Object
- #log_prefix ⇒ Object
- #log_prefix_with(prefix) ⇒ Object
- #log_process(message = '') ⇒ Object
- #log_transaction(message = '') {|transaction_start_time| ... } ⇒ Object
- #tag(*tags) ⇒ Object
- #timestamp ⇒ Object
Class Method Details
.included(other) ⇒ Object
7 8 9 10 |
# File 'lib/exel/processor_helper.rb', line 7 def self.included(other) warn "DEPRECATION WARNING: [#{other}] EXEL::ProcessorHelper will be removed. For process logging, please use "\ 'EXEL::Middleware::Logging instead' end |
Instance Method Details
#ensure_transaction_duration(duration, start_time) ⇒ Object
64 65 66 67 68 |
# File 'lib/exel/processor_helper.rb', line 64 def ensure_transaction_duration(duration, start_time) elapsed_time = Time.now.to_f - start_time.to_f time_to_sleep = duration.second.to_f - elapsed_time sleep(time_to_sleep) if time_to_sleep.positive? end |
#file_size_in_mb(file) ⇒ Object
20 21 22 |
# File 'lib/exel/processor_helper.rb', line 20 def file_size_in_mb(file) format('%.2f MB', file.size.to_f / 1_024_000) end |
#log(message) ⇒ Object
40 41 42 |
# File 'lib/exel/processor_helper.rb', line 40 def log() "#{log_prefix} #{}" end |
#log_error(message) ⇒ Object
36 37 38 |
# File 'lib/exel/processor_helper.rb', line 36 def log_error() EXEL.logger.error(log()) end |
#log_exception(message = '') ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/exel/processor_helper.rb', line 52 def log_exception( = '') yield rescue => e log_error "Exception: #{e..chomp} #{}" log_error e.backtrace.join("\n") raise e end |
#log_info(message) ⇒ Object
32 33 34 |
# File 'lib/exel/processor_helper.rb', line 32 def log_info() EXEL.logger.info(log()) end |
#log_prefix ⇒ Object
28 29 30 |
# File 'lib/exel/processor_helper.rb', line 28 def log_prefix @log_prefix end |
#log_prefix_with(prefix) ⇒ Object
24 25 26 |
# File 'lib/exel/processor_helper.rb', line 24 def log_prefix_with(prefix) @log_prefix = (@context[:log_prefix] || '') + prefix end |
#log_process(message = '') ⇒ Object
60 61 62 |
# File 'lib/exel/processor_helper.rb', line 60 def log_process( = '') log_exception() { log_transaction() { yield } } end |
#log_transaction(message = '') {|transaction_start_time| ... } ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/exel/processor_helper.rb', line 44 def log_transaction( = '') transaction_start_time = Time.now log_info "Started at #{transaction_start_time}" yield(transaction_start_time) transaction_end_time = Time.now log_info "Finished in #{(transaction_end_time - transaction_start_time).to_i} seconds #{}" end |
#tag(*tags) ⇒ Object
12 13 14 |
# File 'lib/exel/processor_helper.rb', line 12 def tag(*) .map { |t| "[#{t}]" }.join('') end |
#timestamp ⇒ Object
16 17 18 |
# File 'lib/exel/processor_helper.rb', line 16 def Time.now.strftime('%m/%e/%y %H:%M') end |