Module: EXEL::ProcessorHelper
- Defined in:
- lib/exel/processor_helper.rb
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
Logging Helpers.
- #log_process(message = '') ⇒ Object
- #log_transaction(message = '') {|transaction_start_time| ... } ⇒ Object
-
#tag(*tags) ⇒ Object
Helper Methods.
- #timestamp ⇒ Object
Instance Method Details
#ensure_transaction_duration(duration, start_time) ⇒ Object
59 60 61 62 63 |
# File 'lib/exel/processor_helper.rb', line 59 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
13 14 15 |
# File 'lib/exel/processor_helper.rb', line 13 def file_size_in_mb(file) format('%.2f MB', file.size.to_f / 1_024_000) end |
#log(message) ⇒ Object
35 36 37 |
# File 'lib/exel/processor_helper.rb', line 35 def log() "#{log_prefix} #{}" end |
#log_error(message) ⇒ Object
31 32 33 |
# File 'lib/exel/processor_helper.rb', line 31 def log_error() EXEL.logger.error(log()) end |
#log_exception(message = '') ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/exel/processor_helper.rb', line 47 def log_exception( = '') yield rescue => e log_error "Exception: #{e..chomp} #{}" log_error e.backtrace.join("\n") raise e end |
#log_info(message) ⇒ Object
27 28 29 |
# File 'lib/exel/processor_helper.rb', line 27 def log_info() EXEL.logger.info(log()) end |
#log_prefix ⇒ Object
23 24 25 |
# File 'lib/exel/processor_helper.rb', line 23 def log_prefix @log_prefix end |
#log_prefix_with(prefix) ⇒ Object
Logging Helpers
19 20 21 |
# File 'lib/exel/processor_helper.rb', line 19 def log_prefix_with(prefix) @log_prefix = (@context[:log_prefix] || '') + prefix end |
#log_process(message = '') ⇒ Object
55 56 57 |
# File 'lib/exel/processor_helper.rb', line 55 def log_process( = '') log_exception() { log_transaction() { yield } } end |
#log_transaction(message = '') {|transaction_start_time| ... } ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/exel/processor_helper.rb', line 39 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
Helper Methods
5 6 7 |
# File 'lib/exel/processor_helper.rb', line 5 def tag(*) .map { |t| "[#{t}]" }.join('') end |
#timestamp ⇒ Object
9 10 11 |
# File 'lib/exel/processor_helper.rb', line 9 def Time.now.strftime('%m/%e/%y %H:%M') end |