Module: Jiggler::Support::Helper

Instance Method Summary collapse

Instance Method Details

#log_error(ex, **ctx) ⇒ Object



14
15
16
17
18
# File 'lib/jiggler/support/helper.rb', line 14

def log_error(ex, **ctx)
  err_context = ctx.compact.map { |k, v| "#{k}=#{v}" }.join(' ')
  logger.error("error_message='#{ex.message}' #{err_context}")
  logger.error(ex.backtrace.first(12).join("\n")) unless ex.backtrace.nil?
end

#log_error_short(err, **ctx) ⇒ Object



20
21
22
23
# File 'lib/jiggler/support/helper.rb', line 20

def log_error_short(err, **ctx)
  err_context = ctx.compact.map { |k, v| "#{k}=#{v}" }.join(' ')
  logger.error("error_message='#{err.message}' #{err_context}")
end

#loggerObject



25
26
27
# File 'lib/jiggler/support/helper.rb', line 25

def logger
  @config.logger
end

#safe_async(name) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/jiggler/support/helper.rb', line 6

def safe_async(name)
  Async do
    yield
  rescue Exception => ex
    log_error(ex, context: name, tid: tid)
  end
end

#scan_all(mask) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/jiggler/support/helper.rb', line 29

def scan_all(mask)
  @config.with_sync_redis do |conn|
    start = '0'
    all_keys = []
    loop do
      start, keys = conn.call('SCAN', start, 'MATCH', mask)
      break if keys.empty?
      all_keys += keys
      break if start == '0'
    end
    all_keys
  end
end

#tidObject



43
44
45
46
# File 'lib/jiggler/support/helper.rb', line 43

def tid
  return unless Async::Task.current?
  (Async::Task.current.object_id ^ ::Process.pid).to_s(36)
end