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

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(message)
  "#{log_prefix} #{message}"
end

#log_error(message) ⇒ Object



36
37
38
# File 'lib/exel/processor_helper.rb', line 36

def log_error(message)
  EXEL.logger.error(log(message))
end

#log_exception(message = '') ⇒ Object



52
53
54
55
56
57
58
# File 'lib/exel/processor_helper.rb', line 52

def log_exception(message = '')
  yield
rescue => e
  log_error "Exception: #{e.message.chomp} #{message}"
  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(message)
  EXEL.logger.info(log(message))
end

#log_prefixObject



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(message = '')
  log_exception(message) { log_transaction(message) { yield } }
end

#log_transaction(message = '') {|transaction_start_time| ... } ⇒ Object

Yields:

  • (transaction_start_time)


44
45
46
47
48
49
50
# File 'lib/exel/processor_helper.rb', line 44

def log_transaction(message = '')
  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 #{message}"
end

#tag(*tags) ⇒ Object



12
13
14
# File 'lib/exel/processor_helper.rb', line 12

def tag(*tags)
  tags.map { |t| "[#{t}]" }.join('')
end

#timestampObject



16
17
18
# File 'lib/exel/processor_helper.rb', line 16

def timestamp
  Time.now.strftime('%m/%e/%y %H:%M')
end