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
6 7 8 9 |
# File 'lib/exel/processor_helper.rb', line 6 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
63 64 65 66 67 |
# File 'lib/exel/processor_helper.rb', line 63 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 > 0 end |
#file_size_in_mb(file) ⇒ Object
19 20 21 |
# File 'lib/exel/processor_helper.rb', line 19 def file_size_in_mb(file) format('%.2f MB', file.size.to_f / 1_024_000) end |
#log(message) ⇒ Object
39 40 41 |
# File 'lib/exel/processor_helper.rb', line 39 def log() "#{log_prefix} #{}" end |
#log_error(message) ⇒ Object
35 36 37 |
# File 'lib/exel/processor_helper.rb', line 35 def log_error() EXEL.logger.error(log()) end |
#log_exception(message = '') ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/exel/processor_helper.rb', line 51 def log_exception( = '') yield rescue => e log_error "Exception: #{e..chomp} #{}" log_error e.backtrace.join("\n") raise e end |
#log_info(message) ⇒ Object
31 32 33 |
# File 'lib/exel/processor_helper.rb', line 31 def log_info() EXEL.logger.info(log()) end |
#log_prefix ⇒ Object
27 28 29 |
# File 'lib/exel/processor_helper.rb', line 27 def log_prefix @log_prefix end |
#log_prefix_with(prefix) ⇒ Object
23 24 25 |
# File 'lib/exel/processor_helper.rb', line 23 def log_prefix_with(prefix) @log_prefix = (@context[:log_prefix] || '') + prefix end |
#log_process(message = '') ⇒ Object
59 60 61 |
# File 'lib/exel/processor_helper.rb', line 59 def log_process( = '') log_exception() { log_transaction() { yield } } end |
#log_transaction(message = '') {|transaction_start_time| ... } ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/exel/processor_helper.rb', line 43 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
11 12 13 |
# File 'lib/exel/processor_helper.rb', line 11 def tag(*) .map { |t| "[#{t}]" }.join('') end |
#timestamp ⇒ Object
15 16 17 |
# File 'lib/exel/processor_helper.rb', line 15 def Time.now.strftime('%m/%e/%y %H:%M') end |